横向和纵向播放视频
Posted
技术标签:
【中文标题】横向和纵向播放视频【英文标题】:Playing video in Landscape and portrait 【发布时间】:2015-05-25 08:42:03 【问题描述】:我的应用处于纵向模式。
当视频播放器进入全屏模式时,我想横向和纵向播放该视频。
moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[moviePlayer.view setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];
[moviePlayer setScalingMode:MPMovieScalingModeFill];
moviePlayer.view.frame = CGRectMake(0, 0, self.videoPlayerView.frame.size.width, self.videoPlayerView.frame.size.height);
[self.videoPlayerView addSubview:moviePlayer.view];
我正在一个按钮上播放它。
【问题讨论】:
你的 rootViewController uinavigationcontroller 或 uitabbarcontroller 是什么?? 问题的标题应该是重点。并在问题正文中使用一些解释。 您是否只是尝试运行应用程序然后打开模拟器?还是实际设备? 【参考方案1】:For you question i would like to give the below Reference
Portrait video to landscape 和
Allow video on landscape with only-portrait app
【讨论】:
【参考方案2】:在部署信息中启用您的横向设备方向。然后,在您的 ViewController 中添加这些方法:
- (BOOL) shouldAutorotate
return NO;
- (NSUInteger) supportedInterfaceOrientations
return UIInterfaceOrientationMaskPortrait;
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
return UIInterfaceOrientationPortrait;
【讨论】:
【参考方案3】:尝试将画布视图作为超级视图添加到您的播放器,并将转换应用到画布视图。
- (void)initialize
self.canvas = [[UIView alloc] initWithFrame: self.view.bounds];
[self.view addSubview:self.canvas];
// init moviePlayer
moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
...
[self.canvas addSubview: moviePlayer.view];
// Add observers
...
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(deviceOrientationDidChange)
name: UIDeviceOrientationDidChangeNotification
object: nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
- (void)deviceOrientationDidChange
// Apply rotation only in full screen mode
if (self.isFullScreen)
UIDeviceOrientation currentOrientation = [UIDevice currentDevice].orientation;
[UIView animateWithDuration: 0.3
animations: ^
CGAffineTransform transform = CGAffineTransformMakeRotation(0);
switch (orientation)
case UIDeviceOrientationLandscapeLeft:
transform = CGAffineTransformMakeRotation(M_PI_2);
break;
case UIDeviceOrientationLandscapeRight:
transform = CGAffineTransformMakeRotation(M_PI + M_PI_2);
break;
default:
break;
;
self.canvas.transform = transform;
self.canvas.frame = self.canvas.superview.bounds;
];
【讨论】:
以上是关于横向和纵向播放视频的主要内容,如果未能解决你的问题,请参考以下文章
Android TV 中的 ExoPlayer 以纵向模式而不是横向模式播放视频