title: Audio playback not returning to original volume in Swift
body: <p>I am trying to play a "Ding" noise to alert the user of an event. The "Ding" plays but the background audio (in this case, the default Music.App) does not return to its original volume after playing the ding. It will return to normal volume after closing the app however. This is what I have:</p>
  
  <p>This is where I set my audio session category:</p>
  
  <pre><code>     public override func viewDidLoad() {
              super.viewDidLoad()
              do {
                  try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: AVAudioSessionCategoryOptions.DuckOthers)
                  //refer to this link for swift's sound reference: https://developer.apple.com/ios/human-interface-guidelines/interaction/audio/
              } catch {
                  print("unable to load audio session")
              }
              ....
       }
  </code></pre>
  
  <p>This is where I call my functions:</p>
  
  <pre><code>if(!currentTimer.launchedNotification){
              playFinishedSound()
              AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate)) //handles phone vibration
              audioPlayerDidFinishPlaying(audioPlayer!, successfully: true)
  
          }
  </code></pre>
  
  <p>And here is my private function: </p>
  
  <pre><code>private func playFinishedSound(){
          if let pathResource = NSBundle.mainBundle().pathForResource("Ding", ofType: "wav"){
              let soundToPlay = NSURL(fileURLWithPath: pathResource)
              do {
                  audioPlayer = try AVAudioPlayer(contentsOfURL: soundToPlay)
                  if(audioPlayer!.prepareToPlay()){
                      print("preparation success")
                      audioPlayer!.delegate = self
                      setAVAudioSession()
                      if(audioPlayer!.play()){
                          print("Sound play success")
                      }else{
                          print("Sound file could not be played")
                      }
                  }else{
                      print("preparation failure")
                  }
  
              }catch{
                  print("Sound file could not be found")
              }
          }else{
              print("path not found")
          }
      }
  </code></pre>
  
  <p>Here is where I set my audio session: </p>
  
  <pre><code>private func setAVAudioSession() {
          let session:AVAudioSession = AVAudioSession.sharedInstance()
          do{
              try session.setActive(true)
              print("session is active")
          }catch{
              print("could not make session active")
          }
      }
  </code></pre>
  
  <p>This is the delegate method for the AVAudioPlayerDelegate protocol:</p>
  
  <pre><code>public func audioPlayerDidFinishPlaying(player: AVAudioPlayer, successfully flag: Bool) {
          do {
              player.stop()
              try AVAudioSession.sharedInstance().setActive(false, withOptions: AVAudioSessionSetActiveOptions.NotifyOthersOnDeactivation)
              player.prepareToPlay()
              print("Session stopped successfully")
          }catch{
              print("Could not end audio session")
          }
      }
  </code></pre>
  
  <p>Again, the problem is that if there is music playing in the background, the music volume will soften, but when the audio session is inactive, the music volume does not return back to normal. </p>