如何在 Apple TV 的 tvOS 上播放视频? [英] How do I play a video on tvOS for Apple TV?

查看:51
本文介绍了如何在 Apple TV 的 tvOS 上播放视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我启动了一个空白的 tvOS 项目并创建了以下代码:

I started a blank tvOS project and created the following code:

- (void)viewDidLoad  
{  
    [super viewDidLoad];  

    AVPlayer *avPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://www.myurl.com/myvideo.mp4"]];  
    AVPlayerLayer *avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];  

    avPlayerLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);  
    [self.view.layer addSublayer:avPlayerLayer];  

    [avPlayer play];  
}  

一旦应用程序加载,模拟器中就不会发生任何事情.没有视频,什么都没有,我的 Apple TV 模拟器中只有一个空白的半透明屏幕.

Nothing happens in the simulator though once the app loads. No video, nothing, just a blank translucent screen in my Apple TV simulator.

从 HTTP 源为 Apple TV 应用在应用启动时播放示例视频的正确方法是什么?

What's the proper way to play a sample video on app launch for an Apple TV app from an HTTP source?

推荐答案

我刚刚将您的代码粘贴到了我的 tvOS 示例项目中,替换了 URL 并运行了它.

I just pasted your code in my tvOS sample project, replaced the URL and ran it.

什么都没发生.好吧,除了有一个日志条目告诉我 App Transport Security 阻止了我的 URL 请求.

Nothing happened. Well, except for the fact that there's a log entry telling me that App Transport Security has blocked my URL request.

所以我前往 Info.plist,禁用 ATS,下次启动时视频显示正常.

So I headed to the Info.plist, disabled ATS and upon next launch the video showed up just fine.

因此,如果您还使用非 HTTPS 网址,则很可能会遇到此问题,通过使用 HTTPS 网址、完全禁用 ATS 或在您的 Info.plist 中允许特定的非 HTTPS 网址可以轻松解决此问题.

So if you're also using a non-HTTPS URL you're very likely running into this issue which is easily fixed by either using an HTTPS URL, disabling ATS completely or allowing specific non-HTTPs URLs in your Info.plist.

P.S.:我使用此视频进行测试.

P.S.: I used this video for testing.

这篇关于如何在 Apple TV 的 tvOS 上播放视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆