title: How can I prevent the app from crashing after pausing the audio?
body: <p>my problem is that my app crashes after pausing the audio. </p>
  
  <pre><code>Thread 1: EXC_BAD_ACCESS (code=1, address=0x48)
  </code></pre>
  
  <p>The sound is played as follows:</p>
  
  <pre><code>var audioPlayer = AVAudioPlayer()
  var jumpAudio: URL?
  var coinAudio: URL?
  ...
  
  duck.run(SKAction.playSoundFileNamed("coin", waitForCompletion: true))
  </code></pre>
  
  <p>I pause the sound in another class by calling this function in the <code>GameScene</code>:</p>
  
  <pre><code>func setAudioOn(pOn: Bool) {
  
      if pOn == true {
          audioPlayer.play()
      }
      else if pOn == false {
          audioPlayer.pause()
      }
  }
  </code></pre>
  
  <p>Thank you in advance</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>(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&lt;UIKit.UITouch&gt; @ 0x00007ffee6bf7838, event=0x00006000008afe70, self=0x00007f91a8d218d0) at settingsView.swift:124:27
      frame #3: 0x000000010905cb18 Ducko`@objc SettingsView.touchesBegan(_:with:) at &lt;compiler-generated&gt;: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
  </code></pre>