【发布时间】:2014-07-14 01:27:54
【问题描述】:
有时 AVPlayer 会以 AVPlayerItemStatusFailed 失败,而在该失败发生后,AVPlayer 会继续以 AVPlayerItemStatusFailed 失败。我试图清除 AVPlayer 实例并创建一个新的,但我无法实现 AVPlayerItemStatusFailed 失败解决。还 removingFromSuperview UIView 使用 AVPlayer 实例并使用 AVPlayer 初始化新项目并不能解决问题。
所以我发现 AVPlayer 无法完全清除。有没有人建议尝试完全清除 AVPlayer 并使其在失败后工作?
错误日志:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x1a689360 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x1a688e70 "The operation couldn’t be completed. (OSStatus error -12983.)", NSLocalizedFailureReason=An unknown error occurred (-12983)}
UPD。 对于@matt
playerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:filePath.path]];
if (!self.avPlayer) {
avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
}
[avPlayer.currentItem addObserver:self forKeyPath:@"status" options:0 context:nil];
if (self.avPlayer.currentItem != self.playerItem) {
[self.avPlayer replaceCurrentItemWithPlayerItem:playerItem];
}
AVPlayerLayer *avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
avPlayerLayer.frame = self.bounds;
[self.layer addSublayer:avPlayerLayer];
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[avPlayer play];
【问题讨论】:
-
显示你的代码 - 你首先用来尝试玩的代码。
-
@matt 感谢您的回答,我在上面添加了我的代码。
-
filePath.path有没有可能是坏的?也许出来为零? -
@matt 链接始终是 mp4 文件,电影始终在 Web 和模拟器中播放,但并不总是在设备上。
标签: ios avfoundation avplayer avplayerlayer avplayeritem