title: Why does my iOS hardware volume control freeze when starting AVAudioPlayer?
body: <p>I am using <code>AVAudioPlayer</code> to play background music in my app. The strange thing is, I cannot adjust volume with the hardware volume buttons when the music is playing. The volume always 'jumps back' to the original. Here is my code:</p>
  
  <pre><code>  do {
       try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
    } catch {    
    }
  
    self.avplayer = AVAudioPlayer(contentsOf: url)
    self.avplayer?.numberOfLoops = -1
    self.avplayer?.prepareToPlay()
    self.avplayer?.play()
  </code></pre>
  
  <p>What did I do wrong?</p>