JEL
JEL

Reputation: 1550

Play video in iOS from a URL

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:

https://r3---sn-ab5l6nzk.googlevideo.com/videoplayback?upn=3VzVwzrmNT8&lmt=1471130096030949&ratebypass=yes&source=youtube&mime=video%2Fmp4&itag=22&pl=27&ipbits=0&expire=1492204641&sparams=dur,ei,expire,id,initcwndbps,ip,ipbits,ipbypass,itag,lmt,mime,mm,mn,ms,mv,pl,ratebypass,requiressl,source,upn&requiressl=yes&ei=AejwWMOXBIiD8wST6aK4CA&dur=663.394&key=cms1&ip=209.95.50.62&id=o-AAVxdc4Jw2onrtv50WYrfSHZNJAfNfmHE5otD3yIdGhU&signature=10A385D37D76E6695D4F49732B0BB3A0DA4F9700.4D0BB88220F8B24145A92AEB384E86432DB6FFC3&redirect_counter=1&req_id=50cca232f5fba3ee&cms_redirect=yes&ipbypass=yes&mm=31&mn=sn-ab5l6nzk&ms=au&mt=1492182931&mv=m

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:

enter image description here

But this other Apple documentation seems to contradict the above: enter image description here

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

Answers (1)

poyo fever.
poyo fever.

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

Related Questions