Reputation: 5666
Hi I have an NSArray containing many 'multimedia action' as I like to call them, objects that encapsulate some multimedia content like movies and photos. I'd like to 'play' them in sequence waiting each one finished before calling the other.
What is the best way to manage the duration of each operation before calling the next one? (for a photo imagine a UIAlertView that dismiss after some seconds delay, for a movie imagine a MPMoviePlayerController instead)
I'm already calling the method that scans the array with an NSOperation.
IMPORTANT: It appears that the MPMovieController does not play (the interface doesn't even appear) whether called inside a NSOperation. Has anyone else experienced this issue?
UPDATE Using performSelectorOnMainThread:
makes the MPMoviePlayer work as expected
Upvotes: 2
Views: 231
Reputation: 5666
This is the solution I've managed to find. I'm posting it in the case anyone is interested.
First I put all my 'multimedia actions' in a NSOperationQueue
and i set the maxConcurrentOperationCount
to 1, so I am certain that they will be run asynchronously from the main thread but only one at a time in a FIFO order (this is very important you you want that your content does not overlap on the screen).
Then for each action I activate it in a particular way depending on its class/kind. Let's suppose there are three kinds of actions:
For the first two I use NSNotifications
to manage the queue since I do not know when the content will stop playing or will be dismissed by the user (suppose by touch). So for each of those I:
setSuspended:YES
setSuspended:NO
For an UIAlertView the notification is posted with a performSelector:withObject:afterDelay:
saying the amount of time it shall be displayed or after a double tap. For A MPMovieController instead it is launched automatically and is named MPMoviePlayerPlaybackDidFinishNotification
. Both the UIAlertView and the MP kind shall be played on the main thread.
The third kind can be a set of instruction simply executed in the NSInvocationOperation put in the queue. So I can even create actions like 'wait' that suspend the queue eecution for some seconds
Upvotes: 1