PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 29, 2022

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

 September 29, 2022     apple-tv, tvos, xcode     No comments   

Issue

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];  
}  

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

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


Solution

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

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

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

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.: I used this video for testing.



Answered By - lemonmojo
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing