在iOS上播放.m3u8文件

时间:2014-03-03 05:28:29

标签: ios video http-live-streaming m3u8

我有.m3u8链接,我需要在支持iOS的{​​{1}}上播放。

当我直接将网址分配给HLS Protocol并播放时,视频不可见,但我可以听到音频。

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]; } 方做些什么其他的事情?

1 个答案:

答案 0 :(得分: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;
}