Screen Shot of AVPlayer error https://i.stack.imgur.com/rX1AT.jpg
下面是代码片段,url是视频url。此错误是随机发生的。
我无法追踪问题所在。此外,视频还存储在云端和视频播放器中,以便在 AVPlayer 上播放。下面的代码中是否缺少任何内容。
+ (void)presentVideoForURL:(NSURL *)URL parentViewController:(UIViewController *)parentViewController {
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *setCategoryError;
if (![audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError]) {
Error(@"setCategoryError %@", setCategoryError.localizedDescription);
}
NSError *activationError;
if (![audioSession setActive:YES error:&activationError]) {
Error(@"activationError: %@", activationError.localizedDescription);
}
AVPlayer *player = [[AVPlayer alloc] initWithURL:URL];
AVPlayerViewController *playerController = [[AVPlayerViewController alloc] init];
playerController.player = player;
[parentViewController presentViewController:playerController animated:YES completion:^{
[player play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish:) name:AVPlayerItemDidPlayToEndTimeNotification object:player.currentItem];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish:) name:AVPlayerItemFailedToPlayToEndTimeNotification object:player.currentItem];
}];
}
检查以下 2 个场景。
1)检查url是否正确。
2)如果您的网络速度很慢并且AVPlayer没有将足够的数据放入其缓冲区,它会停止加载并显示像您提到的UI(播放按钮中的横条)。因此请尝试使用高速网络。
如果这是问题,您可以使用以下命令重新启动播放器播放停止通知.
我遇到了第二个问题,我也像这样修复了同样的问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)