MPMoviePlayerController plays video a second time

I need to be able to play more than one video in an application.

Unfortunately, the second time I press the play button, the video blinks.

I use only this code to play video

NSURL * url = [[[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource: @ "Movie" ofType: @ "m4v"]] autorelease];

MPMoviePlayerController * mp = [[MPMoviePlayerController alloc] initWithContentURL: url];

mp.movieControlMode = MPMovieControlModeDefault;

[mp play];

moviePlayer = mp;

[mp release];

Can someone tell me where the problem might be? Thanks in advance!

UPDATE 1: It seems that the Apple MoviePlayer example has the same problem.

+3
4

, -1.0

mp.initialPlaybackTime = -1.0;

.

+4

MPMoviePlayerController .

:

NSURL *url = [[[NSURL alloc]initFileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Movie" ofType:@"m4v"]] autorelease];

MPMoviePlayerController *mp = [[MPMoviePlayerController alloc]initWithContentURL:url];

mp.movieControlMode = MPMovieControlModeDefault;

//***Add this line***
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:mp];

[mp play];

,

-(void)myMovieFinished:(NSNotification*)aNotification
{
    MPMoviePlayerController *moviePlayer = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidFinishNotification object:moviePlayer];
    [moviePlayer release];
}
+1

, ... 3.1

0
source

I also believe that running on OS 3.1 or a later version of the simulator can play well. It will not blink. But when I add

initialPlaybackTime = -1.0

It will also play well on OS 3.0.

0
source

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


All Articles