8

I'm trying to add an audio input to my AVCaptureSession() and it works great. However I would also like to support users who wish to play music in the background from other apps such as Spotify and maintain this audioInput for my recording. How is this possible?

let captureSession = AVCaptureSession()         
let audioDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio)
audioInput = AVCaptureDeviceInput.deviceInputWithDevice(audioDevice, error:&err) as? AVCaptureDeviceInput
       if captureSession.canAddInput(videoCapture) {
           captureSession.addInput(videoCapture)
           // This line Kills spotify playing in the background
           captureSession.addInput(audioInput as AVCaptureInput)
       }
JZ.
  • 21,147
  • 32
  • 115
  • 192

1 Answers1

0

The category AVAudioSessionCategoryPlayback is one of the few categories that allow for backgrounding. The option AVAudioSessionCategoryOptionMixWithOthers will make sure your audio won’t stop any currently playing background audio and also make sure that when the user plays music in the future, it won’t kick off your background task.

try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: .MixWithOthers)

Maybe this will be helpful

d-link13
  • 21
  • 1
  • 4