doublesymmetry / SwiftAudioEx

SwiftAudioEx is an iOS audio player written in Swift, making it simpler to work with audio playback from streams and files.
Other
150 stars 68 forks source link

Frequently crashed when using audio player event observer. #73

Open Jinya opened 11 months ago

Jinya commented 11 months ago

AppCenter Crash Log

$s12SwiftAudioEx20AVPlayerItemObserverC14startObserving4itemySo0dE0CtFyyScMYccfU AVPlayerItemObserver.swift, line 76 SIGABRT: *** -[AVPlayerItem addOutput:] Cannot attach an output that is already attached or nil output

LAST EXCEPTION BACKTRACE
CoreFoundation
__exceptionPreprocess
libobjc.A.dylib
objc_exception_throw
AVFCore
-[AVPlayerItem(AVPlayerItemOutputs) addOutput:]
OralCraft
$s12SwiftAudioEx20AVPlayerItemObserverC14startObserving4itemySo0dE0C_tFyyScMYccfU_ AVPlayerItemObserver.swift:76
OralCraft
reabstraction thunk helper from @escaping @callee_guaranteed () -> () to @escaping @callee_unowned @convention(block) () -> () <compiler-generated>:0
libdispatch.dylib
_dispatch_client_callout
libdispatch.dylib
_dispatch_continuation_pop
libdispatch.dylib
_dispatch_source_invoke
libdispatch.dylib
_dispatch_main_queue_drain
libdispatch.dylib
_dispatch_main_queue_callback_4CF
CoreFoundation
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
CoreFoundation
__CFRunLoopRun
CoreFoundation
CFRunLoopRunSpecific
GraphicsServices
GSEventRunModal
UIKitCore
-[UIApplication _run]
UIKitCore
UIApplicationMain
OralCraft
main main.swift:11
0x00000001e6290dec

Describe the bug Use Cases

_player.load(item: audioItem, playWhenReady: false)
_player.timeEventFrequency = .custom(time: CMTime(value: 1, timescale: 100))
_player.event.secondElapse.addListener(self) { [weak self] data in
    guard let self else { return }
    if self._player.currentTime > playbackTime.end {
        DispatchQueue.main.async {
            self._player.stop()
            self._player.event.secondElapse.removeListener(self)
        }
    }
}
_player.rate = 1.0
_player.playWhenReady = true
activateSessionIfNeeded()

Smartphone:

bsneed commented 6 months ago

I just tried your example code and was unable to reproduce this with the iOS sample app. You might try a more recent commit; I notice your line numbers are different than what's in the code.