Search code examples
xcodeios8mpmovieplayercontroller

MPMoviePlayerController shows blank screen second time launching


I am using MPMoviePlayerController to play video on iOS.

First time I hit the url and video gets downloaded to documents directory & played well.

Second time I check if the video is already downloaded or not. If not then it goes to server & download it, if yes then it should access it from documents directory and should play video.

but when I fetch video from documents directory then it shows the path well, along with video file name, but it doesn't play the video.

Directly it moves to last view with blank white screen.

What I am doing wrong.

Thanks in advance.

Here is my code.

NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
                NSString *docDir = [arrayPaths objectAtIndex:0];
                NSString* destinationDirectoryPath=docDir;
                NSString *clientPathString = [[NSString alloc] initWithFormat:@"/user"];
                destinationDirectoryPath = [destinationDirectoryPath stringByAppendingString:clientPathString];
                destinationDirectoryPath = [destinationDirectoryPath stringByAppendingString:@"/video1/"];
                NSString *filePath=[NSString stringWithFormat:@"%@",userVideoDTO.learnerid];//@"author";
                filePath=[destinationDirectoryPath stringByAppendingString:[NSString stringWithFormat:@"%@.mp4",filePath]];
                NSLog(@"FilePath new one :- %@",filePath);

self.url = [NSURL fileURLWithPath:filePath];

Then this self.url is passed to MPMoviePlayerController as

self.mp =[[MPMoviePlayerController alloc] initWithContentURL:self.url];

[self.view addSubview:mp.view];
[self.mp play];

What I am missing. Can anyone let me know. This same code is working fine on lower versions of iOS. like iOS7 and below. not on iOS8.

Thanks in advance.


Solution

  • I have been having a similar issue, and it turned out that while in iOS7 and below the containing view controller hadn't had it's -viewWillDisappear:animated: called before the movie player was shown, whereas in iOS8 and going further, it does get called. I was releasing the player and unsubscribing from notifications in -viewWillDisappear:animated:, this time I had to move this code to dealloc.