[英]How to view MPMoviePlayerController FullScreen mode in landscape in iOS?
我想全屏查看MPMoviePlayerController。 它可以是水平視圖。 MPMoviePlayerController只能在縱向視圖中使用。 這是我的代碼嘗試:
創建MPMoviePlayerController:
NSURL *movieURL = [NSURL URLWithString:previewString];
movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[movieController.view setFrame:CGRectMake(10,130, 275 , 150)];
movieController.view.backgroundColor = [UIColor grayColor];
[detailview addSubview:movieController.view];
[movieController prepareToPlay];
movieController.shouldAutoplay = NO;
[detailview addSubview:movieController.view];
我嘗試了上面的代碼但是當moviecontroller是全屏時,它只能以縱向模式查看。 它無法在橫向模式下查看。 我只希望在全屏模式下的電影控制器可以在橫向模式下查看而沒有另一個視圖仍然在縱向模式下查看。 我該怎么辦?
在你的.h文件中
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
並在.m文件中合成該屬性
@synthesize moviePlayer = _moviePlayer;
我的資源文件夾中有電影文件,相應地更改您的姓名:
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"video001" ofType:@"MOV"]]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[_moviePlayer prepareToPlay];
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
[_moviePlayer stop];
[_moviePlayer play];
並關閉fullScreen我有這樣的方法:
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
希望對你有效。
是的,您可以使用兩個通知觀察者來更改完整方向。
首先,在AppDelegate didFinishLaunchingWithOptions
方法中添加兩個通知觀察器:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
第二,添加方法和屬性
- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
self.allowRotation = YES;
}
- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
self.allowRotation = NO;
}
第三,覆蓋supportedInterfaceOrientationsForWindow
方法,您可以返回所需的任何方向
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.allowRotation) {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskPortrait;
}
我在橫向模式下的一個應用程序中使用了以下代碼。
[moviePlayerController.view setFrame:CGRectMake(0, 0, 1024, 768)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
moviePlayerController.repeatMode = MPMovieRepeatModeOne;
moviePlayerController.controlStyle = MPMovieControlStyleNone;
[moviePlayerController play];
您的方法的挑戰在於,只需在視圖中添加子視圖,處理輪換事件就是您的責任。
聽起來你應該使用MPMoviePlayerViewController
:
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:playerController];
[playerController.moviePlayer play];
如果您在應用程序中正確設置了方向選項,則旋轉將由播放器控制器處理,並將同時播放縱向和橫向內容。 如果您的應用目前不支持橫向,則電影播放器控制器也不會。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.