I have been trying to set the frame of the MPMoviePlayerController. But the app is crashing at the line player.view.frame = CGRectMake (0,0,480,320);
in iOS 3.1.3 but works fine on iOS 3.2 or greater. What might be the problem?
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"aVideo.mp4" ofType:@""]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
// Use the new 3.开发者_如何学JAVA2 style API
moviePlayer.repeatMode = YES;
moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
}
else {
Use the old 2.0 style API
moviePlayer.view.frame = CGRectMake (0,0,480,320);
[self.view addSubview: [moviePlayer view]];
moviePlayer.movieControlMode = MPMovieControlStyleDefault;
[moviePlayer play];
}
}
The MPMoviePlayerController reference clearly states the view property is available from iOS3.2 onwards.
view
The view containing the movie content and controls. (read-only)
@property (nonatomic, readonly) UIView *view
Discussion
This property contains the view used for presenting the video content. This view incorporates all the background, content, and controls needed to display movies. You can incorporate this view into your own view hierarchies or present it by itself using a view controller.
To embed the view into your own view hierarchies, add it as a subview to one of your existing views. A good place to do this is in the loadView or viewDidLoad method of the custom view controller that presents your view hierarchy. You are free to change the view’s frame rectangle to accommodate the space available in your view hierarchy. The movie player uses the value in the scalingMode property to scale the movie content to match the frame you specify.
If you want to present the view by itself—that is, without embedding it in an existing view hierarchy—you can use an instance of the MPMoviePlayerViewController class to manage the presentation of the view. That class works directly with the movie player controller to present the view by itself.
You can add subviews to the view in this property. You might do this in cases where you want to display custom playback controls or add other custom content that is relevant to your application.
Availability
- Available in iOS 3.2 and later.
And for iOS 3.1
Behavior in iOS 3.1 and Earlier
In iOS 3.1 and earlier, this class implemented a full-screen movie player only. After creating the movie player and initializing it with a single movie file, you called the play method to present the movie. (The definition of the play method has since moved out of this class and into the MPMediaPlayback protocol.) The movie player object itself handled the actual presentation of the movie content.
What sort of crash is it? Is an exception thrown?
view property available in iOS 3.2 and later for MPMoviePlayerController.
精彩评论