【问题标题】:AVPlayer not playing local videosAVPlayer 不播放本地视频
【发布时间】:2013-07-02 22:24:41
【问题描述】:

我已经为此苦苦挣扎了几个小时... 我正在尝试播放使用 AVPlayer 下载并保存的视频,但没有任何显示。 最让我惊讶的是,如果我使用苹果的示例 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]解决

【问题讨论】:

  • filePath 是如何创建的?
  • 谢谢马丁!我通过使用fileURLWithPath 解决了它
  • 您不应向同一个对象发送多个init/init… 消息。您应该只在第一行创建 AVPlayer,如 [[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:…]]

标签: ios objective-c avfoundation avplayer


【解决方案1】:

只是一小段代码:

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

【讨论】:

  • 我的视频在本地服务器上,我想在我的设备上播放。
  • @Rex 只需更改 NSURL *videoURL = [NSURL URLWithString:@"cdn3.viblast.com/streams/dash/vod-bunny/XXX.mp4"];
  • 是的,我也在用这个。但这不能在设备中播放我的视频
  • @Rex 你能给我一个你的代码要点的链接吗?
  • 我正在使用this。它在模拟器中完美运行。但是当我在真实设备上运行它时,它显示error。请帮忙
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多