我一直在努力解决这个问题...... 我正在尝试播放我下载并使用AVPlayer保存的视频,但没有显示任何内容。 让我感到惊讶的是,如果我使用Apple的示例网址来测试http直播 该视频确实播放。 (http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8) 但是,当我将网址更改为本地文件路径时,视频无法播放。我用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]
解决答案 0 :(得分:3)
只是一小段代码:
NSString *path = [[NSBundle mainBundle] pathForResource:@"splash" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:path];
AVPlayer* player = [AVPlayer playerWithURL:videoURL];