Reputation: 1801
I'm in the process of developing an iPhone app, and I'm running into a very minor issue. Essentially, when I load a certain view, I want the video to play. When the video is done playing it'll return to the view with a menu and some options. One of the options is to replay the video. Currently I have the replay video option working, but I'm unable to play the video when the view is loaded.
I've implemented a playMovie and moviePlayBackDidFinish method. I then placed [self playMovie] in the viewDidLoad method thinking it would call the playMovie method initially and thus play the movie when the view got loaded, but it doesn't seem to work.
If anyone could explain why this method of thinking doesn't work and also a proper way of doing this, it'd be greatly appreciated.
Upvotes: 0
Views: 314
Reputation: 4061
I would try viewDidAppear instead of viewDidLoad depending on your viewController. A view can often only load once, and you may be wasting that as it's loading in the background.
Also, Here's a sample movie Did Finish method, I'm wondering if you're releasing something you shouldn't be, or never telling the movie to stop properly:
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
NSNumber *reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
switch ([reason integerValue])
{
/* The end of the movie was reached. */
case MPMovieFinishReasonPlaybackEnded:
/*
Add your code here to handle MPMovieFinishReasonPlaybackEnded.
*/
break;
/* An error was encountered during playback. */
case MPMovieFinishReasonPlaybackError:
NSLog(@"An error was encountered during playback");
[self performSelectorOnMainThread:@selector(displayError:) withObject:[[notification userInfo] objectForKey:@"error"]
waitUntilDone:NO];
[self removeMovieViewFromViewHierarchy];
[self removeOverlayView];
[self.backgroundView removeFromSuperview];
break;
/* The user stopped playback. */
case MPMovieFinishReasonUserExited:
[self removeMovieViewFromViewHierarchy];
[self removeOverlayView];
[self.backgroundView removeFromSuperview];
break;
default:
break;
}
}
Upvotes: 1