如何在暂停音频后防止应用崩溃?

时间:2019-08-18 16:31:48

标签: swift sprite-kit

我的问题是我的应用程序在暂停音频后崩溃。

Thread 1: EXC_BAD_ACCESS (code=1, address=0x48)

声音播放如下:

var audioPlayer = AVAudioPlayer()
var jumpAudio: URL?
var coinAudio: URL?
...

duck.run(SKAction.playSoundFileNamed("coin", waitForCompletion: true))

我通过在GameScene中调用此函数来暂停另一个类中的声音:

func setAudioOn(pOn: Bool) {

    if pOn == true {
        audioPlayer.play()
    }
    else if pOn == false {
        audioPlayer.pause()
    }
}

提前谢谢

编辑

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x48)
    frame #0: 0x00007fff20a2f58a AVFAudio`-[AVAudioPlayer pause] + 8
  * frame #1: 0x000000010904711d Ducko`GameScene.setAudioOn(pOn=false, self=0x00007f91a9869e00) at GameScene.swift:1305:25
    frame #2: 0x000000010905ca3b Ducko`SettingsView.touchesBegan(touches=Swift.Set<UIKit.UITouch> @ 0x00007ffee6bf7838, event=0x00006000008afe70, self=0x00007f91a8d218d0) at settingsView.swift:124:27
    frame #3: 0x000000010905cb18 Ducko`@objc SettingsView.touchesBegan(_:with:) at <compiler-generated>:0
    frame #4: 0x00007fff2bfc519e SpriteKit`-[SKView touchesBegan:withEvent:] + 1090
    frame #5: 0x00007fff46d9150e UIKitCore`-[UIWindow _sendTouchesForEvent:] + 1867
    frame #6: 0x00007fff46d930f6 UIKitCore`-[UIWindow sendEvent:] + 4596
    frame #7: 0x00007fff46d6e93b UIKitCore`-[UIApplication sendEvent:] + 356
    frame #8: 0x00007fff46dede77 UIKitCore`__dispatchPreprocessedEventFromEventQueue + 6847
    frame #9: 0x00007fff46df093d UIKitCore`__handleEventQueueInternal + 5980
    frame #10: 0x00007fff23ac4241 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    frame #11: 0x00007fff23ac416c CoreFoundation`__CFRunLoopDoSource0 + 76
    frame #12: 0x00007fff23ac3944 CoreFoundation`__CFRunLoopDoSources0 + 180
    frame #13: 0x00007fff23abe64f CoreFoundation`__CFRunLoopRun + 1263
    frame #14: 0x00007fff23abde36 CoreFoundation`CFRunLoopRunSpecific + 438
    frame #15: 0x00007fff37f64bb0 GraphicsServices`GSEventRunModal + 65
    frame #16: 0x00007fff46d562a3 UIKitCore`UIApplicationMain + 1621
    frame #17: 0x000000010905f27b Ducko`main at AppDelegate.swift:12:7
    frame #18: 0x00007fff51175cf5 libdyld.dylib`start + 1
    frame #19: 0x00007fff51175cf5 libdyld.dylib`start + 1

0 个答案:

没有答案