简体   繁体   English

AVPlayer不播放本地视频

[英]AVPlayer not playing local videos

I've been struggling with this for some hours... I'm trying to play a video I download and save using AVPlayer but nothing shows up. 我一直在努力解决这个问题......我正在尝试播放我下载并使用AVPlayer保存的视频,但没有显示任何内容。 What surprised me the most is that if I use Apple's sample url for testing http live streaming that video does play. 让我感到惊讶的是,如果我使用Apple的示例网址来测试视频确实播放的http直播。 ( http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8 ) However, when I change the url to the local file path the video doesn't play. http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8 )但是,当我将网址更改为本地文件路径时,视频无法播放。 I recorded the video with the iPhone and verified that the format (.mov) is playable. 我用iPhone录制了视频并验证了格式(.mov)是否可播放。 Here is the code block: 这是代码块:

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);

Sample output: Playing video at: /var/mobile/Applications/B298EE7D-D95D-4CCC-8466-2C0270E2071E/Documents/394665262.174180.mov 示例输出: Playing video at: /var/mobile/Applications/B298EE7D-D95D-4CCC-8466-2C0270E2071E/Documents/394665262.174180.mov

EDIT: Solved by using [NSURL fileURLWithPath:local_url_string] 编辑:使用[NSURL fileURLWithPath:local_url_string]解决

Just small piece of code: 只是一小段代码:

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