Cocoa-Touch How to: MPMoviePlayerController loop?
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 fa开发者_高级运维des?Try this single line of code:
myPlayer.repeatMode = MPMovieRepeatModeOne;
:)
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 :
- Make sure that the movie starts and ends on the same frame.
- Make the starting frame the Default.png of the app
- On startup add Default.png to the window as a UIImageView
- Make the movie have a clear background
- 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
I don't think there is any public option to do this. You could try and inspect Erica Sadun's Class Dumps for a method you can override that would handle the fading. Maybe a videoDidFinish
method or something.
Have you tried messing around with the backgroundColor property? Apple's MPMoviePlayerController docs say
"The receiver fades to and from the background color when transitioning to and from playback...The default color for this property is black. You can change this to other colors (including clear) to provide a more appropriate transition from your application’s content to the movie content."
So, you can probably try setting it to [UIColor clearColor] and seeing if that helps.
精彩评论