7

Whenever I start an AVCaptureSession running with the microphone as an input it cancels whatever background music is currently running (iPod music for instance). If I comment out the line adding the audio input, the background audio continues.

Does anyone know of a way to record video clips with the microphone while continuing to allow background audio to play? I've looked around a lot, and can't seem to find any references to this behavior.

Thanks for any help!

Edmond
  • 71
  • 1
  • 3

3 Answers3

2

Try setting kAudioSessionProperty_OverrideCategoryMixWithOthers as seen in https://stackoverflow.com/a/7426406/16572

Community
  • 1
  • 1
kalperin
  • 509
  • 5
  • 20
1

Is the background music a looping track? -- if so you could make it a system sound and tell it to re-play when it finishes playing. The reason being you can only have tracks up to 30 seconds as a system sound.

Don't know if it helps -- but thats one approach :)

Cheers,

Michael

Michael O'Brien
  • 256
  • 3
  • 6
0

I had the same problem and used this in my app and it worked:

UInt32 audioRouteOverride = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,sizeof (audioRouteOverride),&audioRouteOverride);

I was able to record video and audio and at the same time play a sound out of the speakers.

Scoota P
  • 2,622
  • 7
  • 29
  • 45
  • Where did you add this? Audio playback from the iPod app always stops, when I add the audio AVCaptureDeviceInput to my capture session… I tried this code before adding this and before creating the capture device… – Haentz Feb 27 '13 at 11:01
  • Where and how to use this? can anyone please explain. – Bhumit Mehta May 24 '14 at 14:36
  • Hi Scoota can you please provide more context? – Noitidart Oct 10 '16 at 18:16