我现在有一个项目,需要将m3u8文件下载到本地才能播放,现在有一种解决方案是通过本地HTTP服务创建已经下载的播放m3u8的文件,有没有一种不需要设置本地HTTP服务,播放本地m3u8文件
您可以使用此代码直接链接播放M3U8文件,
NSString * urlStr = //your URL
NSURL * url = [NSURL URLWithString:urlStr];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
moviePlayer.shouldAutoplay = YES;
moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer prepareToPlay];
[self.view addSubview:moviePlayer.view];
- (void)moviePlaybackComplete:(NSNotification *)notification
{
//Called when playback complete
}
也可以使用NSURL
方法fileURLWithPath:
创建文件URL。