Hia,
I'm looking for a way to play a movie as background in portray mode in my app. The movie should not respond to any taps and my app would have its own buttons and labels over the movi开发者_如何转开发e that control the app.
If you happens to know the Dragons Lair/Space Ace app from iTunes store, something this way.
It seems there are several approaches for playing a m4v file.
Any suggestion which would give me a video playback like described above?
Thanks for reading!
In your app delegate, in application:didFinishLaunchingWithOptions:
you can use this code. Trick is, you still have to show Default.png
before the video plays.
Be sure to add MediaPlayer.framework
to your project
NSString *videoUrl = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
MPMoviePlayerViewController * movieView;
movieView = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:videoUrl]];
MPMoviePlayerController * theMovie = [movieView moviePlayer];
theMovie.scalingMode = MPMovieScalingModeAspectFit;
theMovie.fullscreen = TRUE;
theMovie.controlStyle = MPMovieControlStyleNone;
theMovie.shouldAutoplay = TRUE;
[_window addSubview:movieView.view];
Look at the documentation for MPMoviePlayerController
. It gives you access to a movie player view that you can arbitrarily size and add to your view hierarchy. This is explained in detail in the Class Reference documentation.
Set the player's controlStyle
to MPMovieControlStyleNone
to remove the player controls.
Apple's documentation for MPMoviePlayerController will be very helpful for this task.
Consider a movie player view to be an opaque structure. You can add your own custom subviews to layer content on top of the movie but you must never modify any of its existing subviews.
In addition to layering content on top of a movie, you can provide custom background content by adding subviews to the view in the backgroundView property. (MPMoviePlayerController Class Reference)
The docs further note the real nugget you are after:
This class supports programmatic control of movie playback, and user-based control via buttons supplied by the movie player. You can control most aspects of playback programmatically using the methods and properties of the MPMediaPlayback protocol, to which this class conforms
So, you can:
- Set your MPMoviePlayerController's controlStyle to 'MPMovieControlStyleNone'
- Overlay your own views and controls on top of the player
- Control "playback programmatically using the methods and properties" of the MPMediaPlayback protocol
精彩评论