ios Xcode - Objective C - AVPlayer 以编程方式 - 使用标准/系统皮肤播放本地视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35722451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode - Objective C - AVPlayer programmatically - play local video, with standard/system skin
提问by Henning
Can anyone help me with code for setting up and playing local videofile, using AVPlayer in Xcode? (using AVPlayerLayer, and AVPlayerViewController) All done programmatically and with standard/system videoskin?
任何人都可以帮助我使用 Xcode 中的 AVPlayer 设置和播放本地视频文件的代码吗?(使用 AVPlayerLayer 和 AVPlayerViewController)全部以编程方式完成并使用标准/系统视频皮肤?
Regards Henning
问候亨宁
回答by Chirag Desai
AVPlayer *player = [AVPlayer playerWithURL:"YOUR URL"];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
[self presentViewController:controller animated:YES completion:nil];
controller.player = player;
[player play];
hope this help for you.....
希望这对你有帮助......
回答by Henning
// remote file from server:
NSURL *url = [[NSURL alloc] initWithString:@"https://s3-eu-west-1.amazonaws.com/alf-proeysen/Bakvendtland-MASTER.mp4"];
// create a player view controller
player = [AVPlayer playerWithURL:url];
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = CGRectMake(50,50,500,300);
controller.player = player;
controller.showsPlaybackControls = YES;
player.closedCaptionDisplayEnabled = NO;
[player pause];
[player play];
This is all done in viewDidLoad
and its working fine now. I made a subview to present the player.
这一切都完成了viewDidLoad
,现在工作正常。我做了一个子视图来呈现播放器。
The only thing that is not working now is player.closedCaptionDisplayEnabled = NO;
this is ignored. The video has soft subtitles embedded, and I am able to toggle the subtitles with cc button that is showing. But I am not able to toggle it/control it programmatically?
现在唯一不起作用的是player.closedCaptionDisplayEnabled = NO;
这被忽略了。该视频嵌入了软字幕,我可以使用正在显示的 cc 按钮切换字幕。但我无法以编程方式切换/控制它?