【发布时间】:2011-11-15 14:18:00
【问题描述】:
我正在开发一个应用程序,它可以让我使用 iPhone 在 iPad 上远程播放不同的视频。我一直在关注视频播放器的苹果示例,但我遇到了一些麻烦。视频播放得很好,我可以从各种视频中播放它,但在它们之间切换几次它会崩溃,我在调试器中得到了这个:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An AVPlayerItem cannot be associated with more than one instance of AVPlayer'
*** First throw call stack:
(0x380da8bf 0x37c261e5 0x30acbcb5 0x30abc1f7 0x30ac3bf3 0x30c93d55 0x30c95f7b 0x380ad2dd 0x380304dd 0x380303a5 0x37e07fcd 0x31bb0743 0x25e5 0x257c)
这是我用来创建播放器的代码:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentOfURL:movieURL];
if (player) {
[self setMoviePlayerController:player];
[self installMovieNotificationObservers];
[player setContentURL:movieURL];
[player setMovieSourceType:sourceType];
[self applyUserSettingsToMoviePlayer];
[self.view addSubview:self.backgroundView];
[player.view setFrame:self.view.bounds];
[player.view setBackgroundColor = [UIColor blackColor];
[self.view addSubview:player.view];
}
当当前电影停止时,我使用:
[[self moviePlayerController] stop];
MPMoviePlayerController *player = [self moviePlayerController];
[player.view removeFromSuperview];
[self removeMovieNotificationHandlers];
[self setMoviePlayerController:nil];
编辑: 所以我现在发现每次我第 11 次尝试切换视频时都会发生这种情况。奇怪的!我几乎要拔头发了。
【问题讨论】:
-
在通过 AirPlay 播放视频并允许将应用程序推送到后台时,我遇到了完全相同的错误。有时,当应用程序重新回到前台时,如果包含播放器的视图已被卸载,则恢复应用程序的尝试会因此错误而崩溃。
-
有任何解决方案吗?我在该领域有同样的错误。我的应用程序是一个视频应用程序,可以从网络加载不同的视频。我有多个 mpmoviecontroller 同时处于活动状态,但在任何给定时刻只有一个播放。
-
只是为了增加一点皱纹。这个错误 - 至少在我的情况下,我也希望在 OP 的情况下 - 在“_serverConnectionDiedNotification”被记录后立即被触发。详细信息如下:Info -- notification=Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo=0x42df3e0 {NSLocalizedRecoverySuggestion=稍后再试。, NSLocalizedDescription=Cannot Complete Action}。开始赏金了!先生们!
标签: ios mpmovieplayercontroller