首页 文章

AVPlayer不播放本地视频

提问于
浏览
6

我've been struggling with this for some hours... I'我试图播放我使用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]解决

1 回答

  • 3

    只是一小段代码:

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

相关问题