How to record video and maintain music playing in

2019-03-28 09:34发布

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];

2条回答
\"骚年 ilove
2楼-- · 2019-03-28 09:50

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];
查看更多
Melony?
3楼-- · 2019-03-28 10:04
This fixed it.


[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
                                 withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers
                                       error:nil];
查看更多
登录 后发表回答