在iOS上播放.m3u8文件

7

我有一个 .m3u8 链接,需要在支持 HLS 协议iOS 上播放。

当我将URL直接指定给 MPMoviePlayerController 并播放时,视频不可见但可以听到声音。

NSURL *movieURL = [NSURL URLWithString:@"http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[self.view addSubview:self.moviePlayer.view];

if (mp)
{
    // save the movie player object
    self.moviePlayer = mp;
    [self.moviePlayer setFullscreen:YES];

    // Play the movie!
    [self.moviePlayer play];
}

iOS端,我需要做哪些额外的事情?


1
首先将 self.moviePlayer = mp; 赋值,然后将其设置为全屏 [self.moviePlayer setFullscreen:YES];。那么MPMoviePlayerController视图添加到屏幕的代码在哪里? - iCoder
1
@iCoder:根据您的评论编辑了代码,但仍然没有成功。 - Vip's
1
查看答案! - iCoder
1个回答

10

导入:

#import <MediaPlayer/MediaPlayer.h>

然后执行:

NSURL *movieURL = [NSURL URLWithString:@"http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

if (mp) {
    mp.view.frame = self.view.bounds;
    [self.view addSubview:mp.view];

    // save the movie player object
    [mp setFullscreen:YES];

    // Play the movie!
    [mp play];

    self.moviePlayer = mp;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接