Objective-c – Cocoa-Touch How to: MPMoviePlayerController loop

cocoa-touchiphoneobjective c

I have an app with a splash screen. For the splashscreen I've decided to add a m4v movie. I'm using the MPMoviePlayerController to show the movie. Everything is working as expected except for one thing:

I'm trying to make the MPMoviePlayerController loop by subscribing to it's MPMoviePlayerPlaybackDidFinishNotification notification and issuing a [notification.object play] if the data didn't finish loading.

This works partially, it restarts the movie, but there's the fadeout and re-fadein that make it look bad.

Is there any other way to loop the movie?
Or any way to remove the fades?

Best Answer

By complete coincidence I have just written a blog post on this subject - we ran into this problem while we were writing our latest app :)

Assuming that you don't want to follow my shameless plug, here's how we fixed it :

  1. Make sure that the movie starts and ends on the same frame.
  2. Make the starting frame the Default.png of the app
  3. On startup add Default.png to the window as a UIImageView
  4. Make the movie have a clear background
  5. Play and loop the movie

When the movie ends, it will fade out before it loops round. As Default.png is exactly the same as the start and end frames, the user will never notice :)

When you want to end the movie just remove the Default.png UIImageView and stop the movie - as the background is clear it will just fade out to whatever ui you have in your window.

Sam