我正在开发一个应用程序,我的应用程序仅支持纵向。
支持的方向:
现在我在 viewController 中使用 MPMoviePlayerViewController 。现在需要在横向和纵向模式下显示视频。我怎样才能做到这一点。我用于 MPMovieViewController 的代码是:
-(void) playVideo
{
movieplayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"abc" ofType:@"mp4"]]];
[[NSNotificationCenter defaultCenter] removeObserver:movieplayer
name:MPMoviePlayerPlaybackDidFinishNotification
object:movieplayer.moviePlayer];
// Register this class as an observer instead
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:movieplayer.moviePlayer];
// Set the modal transition style of your choice
movieplayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
movieplayer.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
for(UIView* subV in movieplayer.moviePlayer.view.subviews) {
subV.backgroundColor = [UIColor clearColor];
}
[[movieplayer view] setBounds:CGRectMake(0, 0, 480, 320)];
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI/2);
movieplayer.view.transform = transform;
movieplayer.moviePlayer.fullscreen=YES;
[self presentModalViewController:movieplayer animated:NO];
self.view addSubview:movieplayer.view];
[movieplayer.moviePlayer play];
}
- (void)movieFinishedCallback:(NSNotification*)aNotification
{
NSNumber *finishReason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
MPMoviePlayerController *moviePlayer = [aNotification object];
moviePlayer.fullscreen = NO;
[movieplayer dismissModalViewControllerAnimated:NO];
// Remove this class from the observers
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
}
请给马线索。提前致谢。