MPMoviePlayerController

MPMoviePlayerController

This question already has answers here:
An AVPlayerItem can occupy only one position in a player's queue at a time

(5个答案)


7年前关闭。




这是我的问题,我尝试使用 MPMoviePlayerController 播放流视频,因此我准备将MPMoviePlayerController的视图放在我的自定义viewController中,将controlStyle属性设置为MPMovieControlStyleNone,并在我的init中提供自定义播放器控制器方法:
_moviePlayer = [[MPMoviePlayerController alloc] init];
_moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
_moviePlayer.shouldAutoplay = YES;
_moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
_moviePlayer.controlStyle = MPMovieControlStyleNone;

然后将自定义播放器控件放在moviePlayer上,准备播放时,我会从网络中获取真实的URL,并让moviePlayer进行播放:
_moviePlayer.contentURL = [NSURL URLWithString:url];
[_moviePlayer prepareToPlay];

然后我注册相关通知以报告发生了什么
我提供了简单的seek方法seek,并且只调用了moviePlayer的seek方法,我发现当网络延迟很高时,我尝试在一段时间后崩溃。以及以下调用堆栈:
`0 CoreFoundation 0x381bd8a7 __exceptionPreprocess + 186
1 libobjc.A.dylib 0x334ee259 objc_exception_throw + 32
2 AVFoundation 0x37afb0dd -[AVPlayerItem _attachToPlayer:forImmediateEnqueueing:shouldAppendItem:] + 320
3 AVFoundation 0x37af1edb -[AVPlayer _insertPlaybackItemOfItem:inPlayerQueueAfterPlaybackItemOfItem:] + 42
4 AVFoundation 0x37af2c37 __block_global_0 + 1038
5 libdispatch.dylib 0x34ae5c59 _dispatch_call_block_and_release + 12
6 libdispatch.dylib 0x34ae7ee7 _dispatch_main_queue_callback_4CF$VARIANT$mp + 194
7 CoreFoundation  0x381902ad __CFRunLoopRun + 1268
8   CoreFoundation  0x381134a5 CFRunLoopRunSpecific + 300
9   CoreFoundation  0x3811336d CFRunLoopRunInMode + 104
10  GraphicsServices0x365f6439 GSEventRunModal + 136
11  UIKit 0x30fc4cd5 UIApplicationMain + 1080
12  Player 0x000284dd main + 152
13  Player 0x0001abb8 start + 40
"Exception Name" = NSInvalidArgumentException
"Exception Reason" = "An AVPlayerItem cannot be associated with more than one instance of AVPlayer`

看到期望的原因,我想我可以初始化AVPlayer的多个实例,但是我只有一个MPMoviePlayerController,有人可以指出我的方向吗?谢谢

最佳答案

您尚未显示任何代码,因此无法理解您的问题。问题是您做错了什么,因此如果您需要帮助,则必须准确显示您的工作。

但是,请注意,Apple可能已经在为您提供帮助。您收到的错误消息非常明确:

“Exception Reason” =“一个AVPlayerItem不能与一个以上的AVPlayer实例相关联”

那可能是一个巨大的线索。考虑一下您可能如何违反该规则可能会很有用。

关于iphone - 寻求使用MPMoviePlayerController时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15858722/

10-12 14:43