Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode 14 打包,iOS 16 ,-[AVPlayer replaceCurrentItemWithPlayerItem:] 崩溃 #3725

Closed
ChengzhiHuang opened this issue Nov 24, 2022 · 0 comments · Fixed by #3732
Closed
Assignees

Comments

@ChengzhiHuang
Copy link
Collaborator

ChengzhiHuang commented Nov 24, 2022

推荐收录

链接

一般使用场景是在画中画切换视频的时候需要用到(如果分辨率变了需要加一段黑屏的),适配了 画中画 的 APP 记得处理。

修复方案可以参考:Baseflow/XamarinMediaManager#814

给一个我们自己的修复方案

Before

AVPlayerViewController *vc = ###whatever###;
AVPlayer *player = vc.player;
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path]];
if (player) {
    [player replaceCurrentItemWithPlayerItem:playerItem];
} else {
    player = [AVPlayer playerWithPlayerItem:playerItem];
}

After

AVPlayerViewController *vc = ###whatever###;
AVPlayer *player = vc.player;
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path]];
if (player) {
    AVQueuePlayer *player = (AVQueuePlayer *)player;
    [player removeAllItems];
    [player insertItem:playerItem afterItem:nil];
} else {
    player = [AVQueuePlayer playerWithPlayerItem:playerItem];
}

理由

NSException Cannot remove an observer <NSKeyValueObservance 0x285c78960> for the key path "currentItem.videoComposition" from <AVPlayer 0x28524d760>, most likely because the value for the key "currentItem" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the AVPlayer class.

Thread 0 name:  com.apple.main-thread
Thread 0: Crashed:
0   CoreFoundation                          0x000000019dbea248 ___exceptionPreprocess (in CoreFoundation) + 164
1   libobjc.A.dylib                         0x0000000196fb7a64 _objc_exception_throw (in libobjc.A.dylib) + 56
2   Foundation                              0x000000019811362c -[NSKeyValueNestedProperty object:didRemoveObservance:recurse:] (in Foundation) + 512
3   Foundation                              0x00000001980959ec -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] (in Foundation) + 264
4   Foundation                              0x000000019809588c -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] (in Foundation) + 132
5   Foundation                              0x00000001981134f4 -[NSKeyValueNestedProperty object:didRemoveObservance:recurse:] (in Foundation) + 200
6   Foundation                              0x00000001980959ec -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] (in Foundation) + 264
7   Foundation                              0x000000019809588c -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] (in Foundation) + 132
8   Foundation                              0x000000019809579c -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] (in Foundation) + 192
9   AVKit                                   0x00000001c102ee10 -[AVProxyKVOObserver stopObserving] (in AVKit) + 160
10  AVKit                                   0x00000001c0ffdcd8 -[AVObservationController _stopAllObservation] (in AVKit) + 168
11  AVKit                                   0x00000001c0ffdc0c -[AVObservationController stopAllObservation] (in AVKit) + 36
12  AVKit                                   0x00000001c102ddc0 -[AVVideoFrameVisualAnalyzer _updateObserversIfNeeded] (in AVKit) + 108
13  AVKit                                   0x00000001c102df90 -[AVVideoFrameVisualAnalyzer _updateActualEnabledStateIfNeeded] (in AVKit) + 96
14  AVKit                                   0x00000001c0ffd5b8 ___105-[AVObservationController startObserving:keyPaths:includeInitialValue:includeChanges:observationHandler:]_block_invoke (in AVKit) + 216
15  AVKit                                   0x00000001c0ff2e78 -[AVProxyKVOObserver _handleValueChangeForKeyPath:ofObject:oldValue:newValue:context:] (in AVKit) + 140
16  AVKit                                   0x00000001c0ff2d90 -[AVProxyKVOObserver observeValueForKeyPath:ofObject:change:context:] (in AVKit) + 192
17  Foundation                              0x000000019806b920 _NSKeyValueNotifyObserver (in Foundation) + 248
18  Foundation                              0x0000000198081db0 _NSKeyValueDidChange (in Foundation) + 352
19  Foundation                              0x000000019806ed6c -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] (in Foundation) + 644
20  Foundation                              0x000000019806eabc -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] (in Foundation) + 60
21  Foundation                              0x000000019806e050 __NSSetObjectValueAndNotify (in Foundation) + 280
22  AVKit                                   0x00000001c0feb570 -[AVPlayerController _prepareAssetForInspectionIfNeeded] (in AVKit) + 132
23  AVKit                                   0x00000001c10af5b8 ___30-[AVPlayerController startKVO]_block_invoke_6 (in AVKit) + 28
24  AVKit                                   0x00000001c0ffd5b8 ___105-[AVObservationController startObserving:keyPaths:includeInitialValue:includeChanges:observationHandler:]_block_invoke (in AVKit) + 216
25  AVKit                                   0x00000001c0ff2e78 -[AVProxyKVOObserver _handleValueChangeForKeyPath:ofObject:oldValue:newValue:context:] (in AVKit) + 140
26  AVKit                                   0x00000001c0ff2d90 -[AVProxyKVOObserver observeValueForKeyPath:ofObject:change:context:] (in AVKit) + 192
27  Foundation                              0x000000019806cc88 -[NSKeyValueObservance observeValueForKeyPath:ofObject:change:context:] (in Foundation) + 300
28  Foundation                              0x000000019806b920 _NSKeyValueNotifyObserver (in Foundation) + 248
29  Foundation                              0x0000000198081db0 _NSKeyValueDidChange (in Foundation) + 352
30  Foundation                              0x00000001980d8390 _NSKeyValueDidChangeWithPerThreadPendingNotifications (in Foundation) + 152
31  AVFCore                                 0x00000001ad17c964 ___109-[AVPlayer _runOnIvarAccessQueueOperationThatMayChangeCurrentItemWithPreflightBlock:modificationBlock:error:]_block_invoke_2 (in AVFCore) + 760
32  AVFCore                                 0x00000001ad147dd8 -[AVSerializedMostlySynchronousReentrantBlockScheduler scheduleBlock:] (in AVFCore) + 308
33  AVFCore                                 0x00000001ad1475f4 -[AVPlayer _runOnIvarAccessQueueOperationThatMayChangeCurrentItemWithPreflightBlock:modificationBlock:error:] (in AVFCore) + 372
34  AVFCore                                 0x00000001ad1473d0 -[AVPlayer replaceCurrentItemWithPlayerItem:] (in AVFCore) + 444
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants