繁体   English   中英

AVPlayer不播放本地视频

[英]AVPlayer not playing local videos

我一直在努力解决这个问题......我正在尝试播放我下载并使用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]解决

只是一小段代码:

NSString *path = [[NSBundle mainBundle] pathForResource:@"splash" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:path];
AVPlayer* player = [AVPlayer playerWithURL:videoURL];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM