我正在开发一款应用程序,让我可以通过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)
Run Code Online (Sandbox Code Playgroud)
这是我用来创建播放器的代码:
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];
}
Run Code Online (Sandbox Code Playgroud)
当当前电影停止时,我使用:
[[self moviePlayerController] stop];
MPMoviePlayerController *player = …Run Code Online (Sandbox Code Playgroud)