iPhone开发mpmovieplayer崩溃 [英] iPhone development mpmovieplayer crashing

查看:91
本文介绍了iPhone开发mpmovieplayer崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一款应用程序,让我可以通过iPhone远程在iPad上播放不同的视频。我一直在关注视频播放器的苹果示例,但我遇到了一些麻烦。视频播放得很好,我可以从各种视频播放,但在它们之间切换几次会崩溃,我在调试器中得到这个:

I am working on an app that will let me play different videos on the iPad remotely with an iPhone. I have been following along with apples example for a video player but I've been having some troubles. The videos play just fine and I can get it to play from a variety of videos but switching between them a few times it will crash and i get this in the debugger:

*** 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)

这是我用来创建播放器的代码:

This is the code I am using to create the player:

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];
}

当前电影停止时我使用:

And when the current movie is stopped I use:

[[self moviePlayerController] stop];

MPMoviePlayerController *player = [self moviePlayerController];
[player.view removeFromSuperview];

[self removeMovieNotificationHandlers];
[self setMoviePlayerController:nil];

编辑:
所以我现在发现每当我尝试切换视频时都会发生这种情况第11次。奇怪的!我几乎把头发拉了出来。

So Ive now discovered it happens every time i try and switch a video for the 11th time. weird! I'm practically pulling my hair out.

推荐答案

为我解决这个问题的原因是在执行setContentURL之前停止了MPMoviePlayerController。 / p>

What fixed this problem for me was stopping the MPMoviePlayerController before doing the setContentURL.

    MPMoviePlayerController *streamPlayer;

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

这篇关于iPhone开发mpmovieplayer崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆