从MPMoviePlayerViewController移动到AVPlayer和流m3u8

时间:2016-03-30 22:26:48

标签: objective-c mpmovieplayercontroller avplayer m3u8

我正在尝试从MPMoviePlayerViewController切换到AVPlayer以进行视频播放,我的实现看起来与此类似

NSURL *movieURL = [NSURL URLWithString:@"http://example.com/somefile.m3u8"];
movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
movieController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:movieController];
[movieController.moviePlayer play];

我的AVPlayer版本播放除了所需的m3u8流之外的所有内容。它设法找到该文件,AVPlayerViewController显示正确的文件持续时间,但挂起活动指示,从未真正开始播放。

NSURLComponents *comp = [NSURLComponents componentsWithString:url.absoluteString];

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:comp.URL options:nil];
AVAssetResourceLoader *loader = asset.resourceLoader;
[loader setDelegate:self queue: dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:asset];
self.player = [AVPlayer playerWithPlayerItem:playerItem];

我有一个关于状态的观察者,当AVPlayer的状态为ReadyToPlay时,它最终会播放。 我无法想象AVPlayer可以播放所有内容MPMoviePlayerController,因此AVPlayer版本的正确实现如何才能实现此功能。

1 个答案:

答案 0 :(得分:0)

就像您之前的代码([movieController.moviePlayer play];所做的那样。) 我想你应该开始你的球员 [self.player play];