Search code examples
iosswiftavfoundationavcapturesession

AVCaptureSession, AVCaptureAudioDataOutput and background Music


I record audio/video with AVFoundation using AVCaptureVideoDataOutput and AVCaptureAudioDataOutput. But when I add my AVCaptureAudioDataOutput to my AVCaptureSession, AVFoundation stop background music (in my case from iPod app).

So I'm looking for a solution to let my music playing during my record ?

Thanks,

Alak

ps: I'm targeting iOS8 and I use Swift 2.0


Solution

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