Reputation: 1550
I want to play a videos on iOS from a URL. I don't want to use AVPlayerViewController
by the way.
I’m using youtube-dl
for learning purposes. This gets me the raw url of a video on youtube such as:
I want to learn how to play this on iOS. But I'm not sure if this url refers to:
OR
In the url above, I see there is a Fmp4
, does this mean it’s an HTTP live stream?
Based on this question, it states you can’t directly use an AVURLAsset
. Based on AVFoundation
guide, that seems to be correct. Please see where red arrow is pointing:
But this other Apple documentation seems to contradict the above:
Should I create an AVURLAsset
directly or an AVPlayerItem
directly?
If I create the AVPlayerItem
directly, isn’t this synchronous and therefore will freeze the UI?
Upvotes: 1
Views: 5991
Reputation: 752
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
NSURL *videoURL = [NSURL URLWithString:"your video url"];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
[self presentViewController:playerViewController animated:YES completion:^{
[player play];
}];
Upvotes: 1