8

我已经为此苦苦挣扎了几个小时......我正在尝试播放我下载并使用 AVPlayer 保存的视频,但没有任何显示。最让我吃惊的是,如果我使用 Apple 的示例 url 来测试 http 实时流,视频确实可以播放。(http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8)但是,当我将 url 更改为本地文件路径时,视频不会播放。我用 iPhone 录制了视频,并验证了格式 (.mov) 是可播放的。这是代码块:

AVPlayer *mPlayer = [[AVPlayer alloc] init];
//mPlayer = [mPlayer initWithURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];
mPlayer = [mPlayer initWithURL:filePath];
playerLayer = [AVPlayerLayer playerLayerWithPlayer:mPlayer];
[[[self view] layer] insertSublayer:playerLayer atIndex:3];
[playerLayer setFrame:self.view.bounds];
[mPlayer play];
NSLog(@"Playing video at: %@", filePath);

样本输出: Playing video at: /var/mobile/Applications/B298EE7D-D95D-4CCC-8466-2C0270E2071E/Documents/394665262.174180.mov

编辑:使用 [NSURL fileURLWithPath:local_url_string] 解决

4

1 回答 1

4

只是一小段代码:

NSString *path = [[NSBundle mainBundle] pathForResource:@"splash" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:path];
AVPlayer* player = [AVPlayer playerWithURL:videoURL];
于 2016-06-23T10:26:52.480 回答