MPMoviePlayerController stops playing until the video ends

I am having trouble understanding this class and its proper operation, here is the code fragment in which I use it:

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:_videoURL]; UIImage *videoThumbnail = [moviePlayer thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame]; [lastImageView setImage:videoThumbnail]; [moviePlayer setControlStyle:MPMovieControlStyleNone]; [moviePlayer setShouldAutoplay:YES]; [moviePlayer prepareToPlay]; [moviePlayer.view setFrame:lastImageView.frame]; moviePlayer.view.transform = CGAffineTransformMakeRotation((90*M_PI)/180); [self.view addSubview:moviePlayer.view]; [moviePlayer play]; 

The only reason the video line still exists is because I didn’t receive the video until I tried it to see if the image came from there, and suddenly it started working .. kind of. Now it plays for 2-3 seconds and then ends without sending MPMoviePlayerPlaybackDidFinishNotification or MPMoviePlayerPlaybackStateDidChangeNotification I was looking for a little language and could not find any useful tips, could someone tell me what happened or what I forget

0
source share
1 answer

If you do not assign a newly created instance of MPMoviePlayerController to anything other than a variable with a local scope ( moviePlayer ), then the movie will be released before the movie starts playing. (I believe that calling thumbnailImageAtTime holds it a little longer.)

Try assigning a movie player instance a saved (strong) variable or instance property. Of course, it should be released when done, as multiple instances of the player do not work well.

Also note that with iOS 5, prepareToPlay . The following is chapter 28 of Matt Neuberg. IOS 5 Programming Second Edition:

Before you can display a movie in your interface using MPMoviePlayerController, you must call prepareToPlay, which is provided through the MPMediaPlayer protocol (adopted by MPMoviePlayerController). This requirement is new in iOS 5 and is a significant difference from previous versions of the system; your old code may break if it did not make this call.

+2
source

Source: https://habr.com/ru/post/919870/


All Articles