【发布时间】:2016-10-20 09:30:14
【问题描述】:
我正在开发基于电子书阅读器的应用程序,其中包含多个 PDF 页面。每个页面都有视频图标来播放视频资产。我使用AVPlayer 使用AVPlayerItem 和AVURLAsset(来自URL 的流)播放视频。它可以正常播放来自同一页面或不同页面的相同或不同视频 10-15 次。但一段时间后,视频没有播放,而是显示带有十字线的播放图标。
我使用了下面的代码。
NSURL *videoUrl = [NSURL URLWithString:@"http://WWW.google.com/media/test_1.mp4"]
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
NSDictionary *optionsDic = @{AVURLAssetHTTPCookiesKey : cookies};
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoUrl options:optionsDic];
AVPlayerItem *playeritem = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playeritem];
AVPlayerViewController *moviePlayerVC = [[AVPlayerViewController alloc]init];
moviePlayerVC.player = player;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self presentViewController:moviePlayerVC animated:NO completion:nil];
});
【问题讨论】:
-
你为什么要
dispatch_after? -
我需要一些延迟来显示视频播放器。我一次又一次地尝试不派送,我也面临同样的问题。
-
你叫它form viewDidLoad吗?
-
为“status”添加一个观察者,并在播放失败时检查你得到的状态。
-
@abhi1992,是的,我为“状态”添加了观察者,并收到错误消息为 AVFoundationErrorDomainCode=11839“无法解码”。
标签: ios objective-c avplayer avplayerviewcontroller