iOS 8.4 AVFoundation _attachToPlayer 或 _attachToFigPlayer 崩溃 |一个 AVPlayerItem 不能与多个 AVPlayer 实例相关联
iOS 8.4 AVFoundation _attachToPlayer or _attachToFigPlayer crash | An AVPlayerItem cannot be associated with more than one instance of AVPlayer
我刚刚收到来自 crashlytics 的消息,说我的应用程序稳定性一塌糊涂!基本上这是 iOS (8.4) 的最后一次更新时爆发的崩溃,在以前的版本中是不存在的。
您是否知道什么是 _attachToFigPlayer 或者可能发生了什么导致了这种情况?它发生在两个应用程序中,一个在 Obj-c 中,另一个在 Swift.
中
谢谢大家!
原始崩溃:(_attachToFigPlayer)
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x22adafef __exceptionPreprocess
1 libobjc.A.dylib 0x3141ec8b objc_exception_throw
2 AVFoundation 0x21575b37 -[AVPlayerItem _attachToPlayer:]
3 AVFoundation 0x2156a131 -[AVPlayer _attachItem:andPerformOperation:withObject:]
4 AVFoundation 0x21569347 -[AVPlayer _insertItem:afterItem:]
5 AVFoundation 0x2158744d -[AVQueuePlayer insertItem:afterItem:]
6 MediaPlayer 0x24468c7f -[MPQueuePlayer insertItem:afterItem:]
7 MediaPlayer 0x243e878b -[MPAVQueueCoordinator _syncPlayerItems]
8 MediaPlayer 0x243e8297 -[MPAVQueueCoordinator _syncItems]
9 MediaPlayer 0x243e97e5 __60-[MPAVQueueCoordinator _updateQueueDepthWithPausedDuration:]_block_invoke
10 libdispatch.dylib 0x319af2e3 _dispatch_call_block_and_release
11 libdispatch.dylib 0x319af2cf _dispatch_client_callout
12 libdispatch.dylib 0x319b2d2f _dispatch_main_queue_callback_4CF
13 CoreFoundation 0x22aa0609 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
14 CoreFoundation 0x22a9ed09 __CFRunLoopRun
15 CoreFoundation 0x229eb201 CFRunLoopRunSpecific
16 CoreFoundation 0x229eb013 CFRunLoopRunInMode
17 GraphicsServices 0x2a4bc201 GSEventRunModal
18 UIKit 0x261b7a09 UIApplicationMain
19 MYAPP 0x000d98b3 main (main.m:32)
20 libdyld.dylib 0x319d0aaf start
原始崩溃:(_attachToFigPlayer)
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x0000000182e602d8 __exceptionPreprocess
1 libobjc.A.dylib 0x0000000194ad40e4 objc_exception_throw
2 AVFoundation 0x0000000181634b50 -[AVPlayerItem _attachToFigPlayer]
3 AVFoundation 0x0000000181627770 -[AVPlayer _attachItem:andPerformOperation:withObject:]
4 AVFoundation 0x0000000181648f00 -[AVQueuePlayer insertItem:afterItem:]
5 MediaPlayer 0x0000000185251d30 -[MPQueuePlayer insertItem:afterItem:]
6 MediaPlayer 0x00000001851bde7c -[MPAVQueueCoordinator _syncPlayerItems]
7 MediaPlayer 0x00000001851bd8a4 -[MPAVQueueCoordinator _syncItems]
8 MediaPlayer 0x00000001851bf2fc __60-[MPAVQueueCoordinator _updateQueueDepthWithPausedDuration:]_block_invoke
9 libdispatch.dylib 0x0000000195151994 _dispatch_call_block_and_release
10 libdispatch.dylib 0x0000000195151954 _dispatch_client_callout
11 libdispatch.dylib 0x000000019515620c _dispatch_main_queue_callback_4CF
12 CoreFoundation 0x0000000182e177f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
13 CoreFoundation 0x0000000182e158a0 __CFRunLoopRun
14 CoreFoundation 0x0000000182d412d4 CFRunLoopRunSpecific
15 GraphicsServices 0x000000018c79f6fc GSEventRunModal
16 UIKit 0x000000018793ef40 UIApplicationMain
17 MYAPP 0x00000001001c2e44 main (AppDelegate.swift:17)
18 libdyld.dylib 0x000000019517ea08 start
更新:
这是我在 XCode
中遇到的错误
*** 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'An AVPlayerItem cannot be associated with more than one instance of AVPlayer'
好的,这似乎是在使用 MPMoviePlayerViewController 并尝试重新利用播放器时发生的。在我的例子中,我将播放器用作子视图。
基本上我的解决方法是将播放器设置为 NULL 并在每次播放新视频时重新启动它。
代码:(请记住,我使用 MPMoviePlayerViewController 作为子视图)
- (void)initPlayer {
if (self.player != NULL) {
[self.player.view removeFromSuperview];
self.player = NULL;
}
self.player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:movie]];
if (IsIPad()) {
width = 730;
height = 412;
} else {
width = 320;
height = 180;
}
self.player.view.frame = CGRectMake(0, 61, width, height);
self.player.view.hidden = true;
self.player.moviePlayer.fullscreen = false;
self.player.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
[self.viewController.view addSubview:self.player.view];
}
if(avPlayer==nil)
{
avPlayer = [AVPlayer playerWithPlayerItem:_avPlayerItem];
}else{
[avPlayer replaceCurrentItemWithPlayerItem:_avPlayerItem];
}
这将解决此类问题
我刚刚收到来自 crashlytics 的消息,说我的应用程序稳定性一塌糊涂!基本上这是 iOS (8.4) 的最后一次更新时爆发的崩溃,在以前的版本中是不存在的。
您是否知道什么是 _attachToFigPlayer 或者可能发生了什么导致了这种情况?它发生在两个应用程序中,一个在 Obj-c 中,另一个在 Swift.
中谢谢大家!
原始崩溃:(_attachToFigPlayer)
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x22adafef __exceptionPreprocess
1 libobjc.A.dylib 0x3141ec8b objc_exception_throw
2 AVFoundation 0x21575b37 -[AVPlayerItem _attachToPlayer:]
3 AVFoundation 0x2156a131 -[AVPlayer _attachItem:andPerformOperation:withObject:]
4 AVFoundation 0x21569347 -[AVPlayer _insertItem:afterItem:]
5 AVFoundation 0x2158744d -[AVQueuePlayer insertItem:afterItem:]
6 MediaPlayer 0x24468c7f -[MPQueuePlayer insertItem:afterItem:]
7 MediaPlayer 0x243e878b -[MPAVQueueCoordinator _syncPlayerItems]
8 MediaPlayer 0x243e8297 -[MPAVQueueCoordinator _syncItems]
9 MediaPlayer 0x243e97e5 __60-[MPAVQueueCoordinator _updateQueueDepthWithPausedDuration:]_block_invoke
10 libdispatch.dylib 0x319af2e3 _dispatch_call_block_and_release
11 libdispatch.dylib 0x319af2cf _dispatch_client_callout
12 libdispatch.dylib 0x319b2d2f _dispatch_main_queue_callback_4CF
13 CoreFoundation 0x22aa0609 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
14 CoreFoundation 0x22a9ed09 __CFRunLoopRun
15 CoreFoundation 0x229eb201 CFRunLoopRunSpecific
16 CoreFoundation 0x229eb013 CFRunLoopRunInMode
17 GraphicsServices 0x2a4bc201 GSEventRunModal
18 UIKit 0x261b7a09 UIApplicationMain
19 MYAPP 0x000d98b3 main (main.m:32)
20 libdyld.dylib 0x319d0aaf start
原始崩溃:(_attachToFigPlayer)
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x0000000182e602d8 __exceptionPreprocess
1 libobjc.A.dylib 0x0000000194ad40e4 objc_exception_throw
2 AVFoundation 0x0000000181634b50 -[AVPlayerItem _attachToFigPlayer]
3 AVFoundation 0x0000000181627770 -[AVPlayer _attachItem:andPerformOperation:withObject:]
4 AVFoundation 0x0000000181648f00 -[AVQueuePlayer insertItem:afterItem:]
5 MediaPlayer 0x0000000185251d30 -[MPQueuePlayer insertItem:afterItem:]
6 MediaPlayer 0x00000001851bde7c -[MPAVQueueCoordinator _syncPlayerItems]
7 MediaPlayer 0x00000001851bd8a4 -[MPAVQueueCoordinator _syncItems]
8 MediaPlayer 0x00000001851bf2fc __60-[MPAVQueueCoordinator _updateQueueDepthWithPausedDuration:]_block_invoke
9 libdispatch.dylib 0x0000000195151994 _dispatch_call_block_and_release
10 libdispatch.dylib 0x0000000195151954 _dispatch_client_callout
11 libdispatch.dylib 0x000000019515620c _dispatch_main_queue_callback_4CF
12 CoreFoundation 0x0000000182e177f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
13 CoreFoundation 0x0000000182e158a0 __CFRunLoopRun
14 CoreFoundation 0x0000000182d412d4 CFRunLoopRunSpecific
15 GraphicsServices 0x000000018c79f6fc GSEventRunModal
16 UIKit 0x000000018793ef40 UIApplicationMain
17 MYAPP 0x00000001001c2e44 main (AppDelegate.swift:17)
18 libdyld.dylib 0x000000019517ea08 start
更新:
这是我在 XCode
中遇到的错误*** 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'An AVPlayerItem cannot be associated with more than one instance of AVPlayer'
好的,这似乎是在使用 MPMoviePlayerViewController 并尝试重新利用播放器时发生的。在我的例子中,我将播放器用作子视图。
基本上我的解决方法是将播放器设置为 NULL 并在每次播放新视频时重新启动它。
代码:(请记住,我使用 MPMoviePlayerViewController 作为子视图)
- (void)initPlayer {
if (self.player != NULL) {
[self.player.view removeFromSuperview];
self.player = NULL;
}
self.player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:movie]];
if (IsIPad()) {
width = 730;
height = 412;
} else {
width = 320;
height = 180;
}
self.player.view.frame = CGRectMake(0, 61, width, height);
self.player.view.hidden = true;
self.player.moviePlayer.fullscreen = false;
self.player.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
[self.viewController.view addSubview:self.player.view];
}
if(avPlayer==nil)
{
avPlayer = [AVPlayer playerWithPlayerItem:_avPlayerItem];
}else{
[avPlayer replaceCurrentItemWithPlayerItem:_avPlayerItem];
}
这将解决此类问题