Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController iO7 issue

I am trying to play a video stored in my application's documents directory through MPMoviePlayerController. I am using the following method to play video:

NSArray *directoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [directoryPath objectAtIndex:0];
int videoNumber = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"videoSaved"];
NSString* videoName = [NSString stringWithFormat:@"video-%d.mov",videoNumber];
NSString *exportPath = [docsDir stringByAppendingPathComponent:videoName];
NSURL *exportUrl = [NSURL fileURLWithPath:exportPath isDirectory:NO];

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:exportUrl];
moviePlayer.fullscreen = YES;
moviePlayer.view.frame = self.view.bounds;
[self.view addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movieDidExitFullscreen:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

It works fine on all iOS versions except iOS7. In iOS7 when i try to play video it ives me this error:

_itemFailedToPlayToEnd: {    kind = 1;    new = 2;    old = 0;}
like image 687
EXC_BAD_ACCESS Avatar asked Nov 01 '22 13:11

EXC_BAD_ACCESS


1 Answers

Try to change your code to this:

int videoNumber = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"videoSaved"];

moviePlayer= [[MPMoviePlayerController alloc] initWithContentURL:
    [NSURL fileURLWithPath: [[NSBundle mainBundle] 
    pathForResource: [NSString stringWithFormat:@"video-%d",videoNumber] ofType:@"mov"]]];

moviePlayer.fullscreen = YES;
moviePlayer.movieSourceType = MPMovieSourceTypeFile;
moviePlayer.view.frame = self.view.bounds;
[self.view addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movieDidExitFullscreen:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];
like image 75
Mutawe Avatar answered Nov 15 '22 14:11

Mutawe