Videos start but hang after a few seconds with MPMoviePlayerViewController

advertisements

The method I use to play the video is:

-(void)playVideo:(NSString*)title {

NSLog(@"NAME: %@", title);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *moviePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4", title]];

MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];

mp.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

[self presentMoviePlayerViewControllerAnimated:mp];

[mp release];
}

After around 4 or 5 seconds the video stops, the previous screen is shown and I get the following error:

_itemFailedToPlayToEnd: {
AVPlayerItemFailedToPlayToEndTimeErrorKey = "Error Domain=AVFoundationErrorDomain Code=-11800 \"The operation could not be completed\" UserInfo=0xb19a220 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0xb17fac0 \"The operation couldn\U2019t be completed. (OSStatus error -12551.)\", NSLocalizedFailureReason=An unknown error occurred (-12551)}";


Try in Simple steps:

Step 1: Import MediaPlayer framework #import <MediaPlayer/MediaPlayer.h>

Step 2: Set delegate in .h file UIViewController<MPMediaPlayback>

Step 3:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *fileLocation= [bundle pathForResource:@"file_video" ofType:@"m4v"];
    NSURL *vedioURL =[NSURL fileURLWithPath:fileLocation];
    MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:vedioURL];
    [self presentMoviePlayerViewControllerAnimated:videoPlayerView];
    [videoPlayerView.moviePlayer play];
}

-(void)endSeeking
{
    [self.navigationController popViewControllerAnimated:NO];
}

-(void)stop
{
    [self.navigationController popViewControllerAnimated:NO];
}