I have an app that needs to have:

Background music playing while using the app (eg. spotify)

Background music playing while watching movie from AVPlayer

Stop the music when recording a video

Like Snapchat, the camera-viewcontroller is part of a "swipeview" and therefore always on.

However, when opening and closing the app, the music makes a short "crack" noise/sound that ruins the music.

I recorded it here: https://soundcloud.com/morten-stulen/hacky-sound-ios (3 occurrences)

I use these settings for changing the AVAudiosession in the appdelegate didFinishLaunchingWithOptions:

do { try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord,withOptions: [AVAudioSessionCategoryOptions.MixWithOthers, AVAudioSessionCategoryOptions.DefaultToSpeaker]) try AVAudioSession.sharedInstance().setActive(true) } catch { print("error") }

I use the LLSimpleCamera control for video recording and I've set the session there to:

_session.automaticallyConfiguresApplicationAudioSession = NO;

It seems others have the same problem with other camera libraries as well: https://github.com/rFlex/SCRecorder/issues/127

https://github.com/rFlex/SCRecorder/issues/224

This guy removed the audioDeviceInput, but I kinda need that for recording video. https://github.com/omergul123/LLSimpleCamera/issues/48

I also tried with Apple's code "AvCam", and I still have the same issue. How does Snapchat do this?!

Any help would be greatly appreciated, and I'll gladly provide more info or code!