这是我的问题,我尝试使用MPMoviePlayerController播放流视频,所以我准备将MPMoviePlayerController
's 视图放在我的自定义 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,任何人都可以为我指明方向吗?谢谢