views:

350

answers:

2

Hi, everyone. It's really wired. When at the first time a MPMoviePlayerController (e.g., theMovie) is created, its initialPlaybackTime can be set successfully. But when theMoive is released and re-create a new MPMoviePlayerController, its intialPlaybackTime can not be set correctly, actually the movie always plays from the start. The code is as follows.

-(void)initAndPlayMovie:(NSURL *)movieURL {

MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

// create a notification for moviePlaybackFinish
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];

theMovie.initialPlaybackTime = 15;
[theMovie setScalingMode:MPMovieScalingModeAspectFill];
[theMovie play];}

-(void) moviePlayBackDidFinish:(NSNotification*)notification { MPMoviePlayerController * theMovie = [notification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie]; [theMovie release]; [self initAndPlayMovie:[self getMovieURL]]; }

With the above code, when the viewcontroller did load and run initAndPlayMovie, the movie starts to play from 15 seconds, but when it plays finished or "Done" is pushed, a new theMovie is created and starts to play from 0 second. Does anybody know what happened with the initialPlaybackTime property of MPMoviePlayerController?

And whenever you reload the viewController where the above code is (presentModalViewController from a parent viewcontroller), the movie can start from any playback time. I am really confused what's the difference of the MPMoviePlayerController registration methods between the viewcontroller load and the recreating it after release.

Need your help! Thank you!

A: 

The problem has been resolved! It needs one step to make the initialPlaybackTime setting properly.

after release the movieplayer, 1-second delay is needed before starting play again. Make sure the movieplayer is released completely.

It took me 3 days to figure out the issue. But now my question is how I can detect if a movieplayer has been released completely rather than to wait for one second.

vicky
A: 

After you have released your theMovie, give it a value nil

[theMovie released]; theMovie = nil;

then you can tell if it released already.

if (theMovie == nil){
//do something here when movie player is released already
}

Winux