title: Using Spotify/background music with camera open
body: <p>I have an app that needs to have:</p>
  
  <ul>
  <li>Background music playing while using the app (eg. spotify)</li>
  <li>Background music playing while watching movie from AVPlayer</li>
  <li>Stop the music when recording a video</li>
  </ul>
  
  <p>Like Snapchat, the camera-viewcontroller is part of a "swipeview" and therefore always on.</p>
  
  <p><strong>However, when opening and closing the app, the music makes a short "crack" noise/sound that ruins the music.</strong> </p>
  
  <p>I recorded it here:
  <a href="https://soundcloud.com/morten-stulen/hacky-sound-ios">https://soundcloud.com/morten-stulen/hacky-sound-ios</a>
  (3 occurrences)</p>
  
  <p>I use these settings for changing the AVAudiosession in the appdelegate didFinishLaunchingWithOptions:</p>
  
  <pre><code>     do {
              try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord,withOptions: 
                  [AVAudioSessionCategoryOptions.MixWithOthers,
                   AVAudioSessionCategoryOptions.DefaultToSpeaker])
              try AVAudioSession.sharedInstance().setActive(true)
  
          } catch {
              print("error")
          }
  </code></pre>
  
  <p>I use the LLSimpleCamera control for video recording and I've set the session there to:</p>
  
  <pre><code>_session.automaticallyConfiguresApplicationAudioSession = NO;
  </code></pre>
  
  <p>It seems others have the same problem with other camera libraries as well:
  <a href="https://github.com/rFlex/SCRecorder/issues/127">https://github.com/rFlex/SCRecorder/issues/127</a></p>
  
  <p><a href="https://github.com/rFlex/SCRecorder/issues/224">https://github.com/rFlex/SCRecorder/issues/224</a></p>
  
  <p>This guy removed the audioDeviceInput, but I kinda need that for recording video.
  <a href="https://github.com/omergul123/LLSimpleCamera/issues/48">https://github.com/omergul123/LLSimpleCamera/issues/48</a></p>
  
  <p>I also tried with Apple's code "AvCam", and I still have the same issue. How does Snapchat do this?!</p>
  
  <p>Any help would be greatly appreciated, and I'll gladly provide more info or code!</p>