Sorry if this is a duplicate, but I couldn't find a question similar to this. I have a custom camera/recorder that I made with AVFoundation and I was wondering how to keep the audio running from other apps while recording a video because right now it stops the audio (doesn't even pause it) and then records the video
If I am thinking correctly, could this be solved by adding something similar to this:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
Visit Play Store and install Play Music While Recording app. Start playing music you want to hear while recording. Open the Installed app and stay in Video mode. Start recording your video by tap on camera icon.
From the Home screen, tap Apps > Music Player . Tap a song in your library to listen to it. Tap the Menu Key > Settings and checkmark the Show notification option so that the music controller is displayed on the Notifications panel.
Sample Code:
AVAudioSession *session = [AVAudioSession sharedInstance];
session.delegate = self;
NSError *error = nil;
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
OSStatus propertySetError = 0;
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
propertySetError = AudioSessionSetProperty (
kAudioSessionProperty_OverrideAudioRoute,
sizeof (audioRouteOverride),
&audioRouteOverride
);
[session setActive:YES error:&error];
This fixed it.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers
error:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With