tags:

views:

92

answers:

2

I am wondering how to most efficiently play a series of video with MPMoviePlayerViewController?

For example, I would like to play in a series the following:

Video1.mp4 Video2.mp4 Video3.mp4

and so on...

Any suggestions appreciated.

A: 

Use NSNotificationCenter to monitor for the MPMoviePlayerPlaybackDidFinishNotification notification. Then, set up the player with the next item you wish to play.

jtbandes
I do have the callback registered. I do have the filenames in an array I can track. Are you suggesting adding the play methods to the MPMoviePlayerPlaybackDidFinishNotification? Thanks. //---play movie--- MPMoviePlayerController *player = [playerViewController moviePlayer]; [player play];
butchcowboy
Yes, but you'll want to use `-setContentURL:` to set it to the next movie, then play it.
jtbandes
Thanks but still having issues. For some reason I cannot access the array that holds the fileNames. This code works in viewDidLoad but throws exception from the MPMoviePlayerPlaybackDidFinishNotificaition. This is the code to access an array of strings. How can I access this array from the callback? NSString *string = [arrayBrotherPirateEnglish objectAtIndex: 2]; 2010-07-26 14:13:17.391 BookReaderJuly23[51927:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFType objectAtIndex:]: unrecognized selector sent to instance 0x5340b10'
butchcowboy
You'll need to make sure you're retaining the array so it stays around long enough to use when the notification is called.
jtbandes
Added retain to the array. Now, the movieFinished callback is not even being fired and I'm getting this.2010-07-26 21:54:06.544 EJStoriesVol1[67297:207] *** -[VideoPlaybackViewController moviePlayBackDidFinish:]: unrecognized selector sent to instance 0x53625802010-07-26 21:54:06.551 EJStoriesVol1[67297:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[VideoPlaybackViewController moviePlayBackDidFinish:]: unrecognized selector sent to instance 0x5362580'
butchcowboy
Please disregard above comment. Name change problem.
butchcowboy
i made all my instance variables properties and now all is good. one question? should i remove the observer:MPMoviePlayerPlaybackDidFinishNotification before each new video is played or after the entire series?
butchcowboy
After the whole series, otherwise you'll stop getting the notifications. Since you're using the same MoviePlayer for all the videos, you don't have to change the notification stuff in between.
jtbandes
A: 

You can register for the notification MPMoviePlayerPlaybackDidFinishNotification with [NSNotificationCenter defaultCenter]. Once you receive that notification, just load the next video and start playback.

Have a look at the respective class documentations for additional details.

Benjamin