THM*_*THM 13 cocoa avfoundation uikit ios avplayer
我的崩溃影响了大约10%的用户,但我无法重现它,并且不确切知道何时发生这种情况.
Crashlytics报告了大约一半的崩溃用户没有关注应用程序,即做背景音频或AirPlay.该应用程序播放HLS视频流,并在背景时切换到仅音频版本.
任何想法有什么问题,或者为什么我的单例播放器类会有多个AVPlayer实例?
谢谢!
Exception Type:
NSInvalidArgumentException
Reason:
An AVPlayerItem cannot be associated with more than one instance of AVPlayer
Fatal Exception
Latest Crash: 4/06/2013 at 8:48:46 UTC+0200
0 CoreFoundation __exceptionPreprocess + 162
1 libobjc.A.dylib objc_exception_throw + 30
2 AVFoundation -[AVPlayerItem _attachToPlayer:] + 188
3 AVFoundation -[AVPlayer _attachItem:andPerformOperation:withObject:] + 336
4 AVFoundation -[AVPlayer _insertItem:afterItem:] + 26
5 AVFoundation -[AVQueuePlayer insertItem:afterItem:] + 136
6 MediaPlayer __block_global_4 + 520
7
...
libdispatch.dylib _dispatch_call_block_and_release + 10
14
Run Code Online (Sandbox Code Playgroud)
似乎可以通过在设置新URL之前明确停止播放来解决,例如
[moviePlayer stop];
moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[moviePlayer setContentURL:[NSURL URLWithString:[videos objectForKey:quality]]];
Run Code Online (Sandbox Code Playgroud)
找到此问题的原因...如果创建了 MovieViewController,并且当前正在缓冲(即状态!= MPMovieLoadStatePlayable 或 MPMovieLoadStatePlaythroughOK),则调用“play”方法将使应用程序崩溃并出现此异常。