ios - 如何在 AVPlayer 中默认以横向模式播放视频?
问题描述
- (void)playMethod
{
NSURL *url = [[NSURL alloc] initWithString:@"https://www.rmp-
streaming.com/media///bbb-360p.mp4"];
player = [AVPlayer playerWithURL:url];
controller = [[AVPlayerViewController alloc] init];
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = CGRectMake(15,50,345,300);
controller.player = player;
controller.showsPlaybackControls = YES;
player.closedCaptionDisplayEnabled = NO;
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 addTarget:self
action:@selector(backMethod)
forControlEvents:UIControlEventTouchUpInside];
[button1 setTitle:@"Back" forState:UIControlStateNormal];
[button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
button1.frame = CGRectMake(50.0, CGRectGetMinY(controller.view.frame)+10, 160.0, 40.0);
button1.tag = 1001;
[self.view addSubview:button1];
[controller.view bringSubviewToFront:button1];
[player pause];
[player play];
}
我现在想以横向模式播放视频,它以纵向模式播放。我希望在调用 playMethod 时它应该只以横向模式打开视频。
解决方案
创建从 AVPlayerViewController 继承的自定义类并使用它而不是基本 AVPlayerViewController
import AVKit
class CustomAVPlayerViewController: AVPlayerViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeLeft
}
}
推荐阅读
- c# - 如何从不同的脚本访问和禁用游戏对象 - Unity2D
- python - 如何显示csv文件中的数据
- tooltip - 是否可以在 Qualtrics 的工具提示上显示图像而不是文字?
- javascript - React Native 中的连续 SVG Wave 动画
- angular - 使用 Active Directory 令牌从 Angular 到 Web API 应用程序进行安全 API 调用
- git - Manually adding a file with a merge-conflict to the git index by setting non-zero stage entry values
- php - Cake PHP PatchEntities 拯救了 epoc
- python - 应用自定义函数并每 N 行写入 CSV
- heroku - 如何在 Heroku 上部署 Jhipster getaway 应用程序
- sql - 使用满足命令行的 powershell -Query 选项识别进程,例如 '%pattern%'