[英]iPhone: MPMoviePlayerController doesn't rotate on iOS 5.0
在將iPhone升級到iOS 5.0之前,我的代碼工作正常。 MPMoviePlayerViewController過去可以正常工作,但在iOS 5.0上不起作用,因此我必須對iOs 5.0和更高版本使用MPMoviePlayerController。 它工作正常,但MPMoviePlayerController不會像以前使用MPMoviePlayerViewController那樣自動旋轉。
以下是我的代碼。 有人可以建議我如何使MPMoviePlayerController代碼自動旋轉嗎?
-(void)playVideo {
NSString *filePath = [appDelegate filePath:@"startup.mp4"];
if(!appDelegate.iOS5) {
// This works perfectly till iOS 4 versions. Rotates automatically
MPMoviePlayerViewController *videoController = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:filePath]] autorelease];
[self presentMoviePlayerViewControllerAnimated:videoController];
} else {
// This doesn't rotate automatically
NSURL *url = [NSURL fileURLWithPath:filePath];
MPMoviePlayerController* moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL:url] autorelease];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
嘗試對MPMoviePlayerController進行子類化,並將方向強制為僅縱向。
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
不是最好的解決方案,但我認為它應該可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.