ios – iPhone开发mpmovieplayer崩溃

前端之家收集整理的这篇文章主要介绍了ios – iPhone开发mpmovieplayer崩溃前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用一个应用程序,让我可以使用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次.奇怪的!我几乎把我的头发拉出来

解决方法

什么修复了我的这个问题是在执行setContentURL之前停止MPMoviePlayerController.
MPMoviePlayerController *streamPlayer;

    [streamPlayer stop];
    [streamPlayer setContentURL:[NSURL URLWithString:selectedStation]];

猜你在找的iOS相关文章