How do I play a video on tvOS for Apple TV?

前端 未结 6 1330
北荒
北荒 2020-12-24 02:29

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

- (void)viewDidLoad  
{  
    [super viewDidLoad];  

    AVPlayer *avPlayer = [AVPlayer playe         


        
6条回答
  •  庸人自扰
    2020-12-24 03:05

    The best way to play video in your app on AppleTV is going to be AVKit's AVPlayerViewController. If you use AVKit, you get a lot of stuff for free.

    https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayerViewController_Class/index.html

    You simply add that player to the viewController's player property:

    // instantiate here or in storyboard
    AVPlayerViewController *viewController = [[AVPlayerViewController alloc] initWithNibName:nil bundle:nil];
    viewController.player = player;
    
    [self addChildViewController:viewController];
    [self.view addSubview:viewController.view];
    [viewController didMoveToParentViewController:self];
    
    // setup constraints, etc.
    
    // play the video
    [player play];
    

    Also as mentioned below, make sure the video you're trying to play is coming either from an HTTPS connection or that you've disabled App Transport Security by setting the proper flags in the plist.

提交回复
热议问题