rFlex / SCRecorder

iOS camera engine with Vine-like tap to record, animatable filters, slow motion, segments editing
Apache License 2.0
3.06k stars 583 forks source link

Stop and resume background music. #325

Open Tejas-narola opened 8 years ago

Tejas-narola commented 8 years ago

I want continue playing background music as camera initialised and after capturing photo or recording video, i come back to camera screen , the background music should be resume .

I have set automaticallyConfiguresApplicationAudioSession = NO in - (id)init method of SCRecorder.m file for playing background music when camera initialised but after capturing image or recording video ,i again came back to camera screen at that background music is not resuming.

I have set category in appDelegate.m file.

`- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {

dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
    // Add code here to do background processing
    //
    //

    AVAudioSession *session1 = [AVAudioSession sharedInstance];
    [session1 setCategory:AVAudioSessionCategoryPlayAndRecord  withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowBluetooth error:nil];
     [session1 setActive:YES error:nil];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

    dispatch_async( dispatch_get_main_queue(), ^{
        // Add code here to update the UI/send notifications based on the
        // results of the background processing
    });
});

`

please help me to handle audio session manually.

aprato commented 8 years ago

see my answer here: https://github.com/rFlex/SCRecorder/issues/331 Two key parts. One is timing. I was going to play and record on view did appear of my camera and going to ambient on view will disappear. Second key part seems to be setting the audio session active=NO before making a category change and active=YES after the category change

Olive-l commented 7 years ago

@Tejas-narola I come to the same issue. When opening the SCRecoder view, will stop the background music automatically. But when close SCRecorder view, the background music can't be resumed. Have you fixed this problem? I tried reset the AVAudioSession after SCRecoder closed, but it's not work for me.

AVAudioSession` *audioSession=[AVAudioSession sharedInstance];
if (audioSession) {
[audioSession setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
}

@aprato I tried your code too, before SCRecorder setup. it can't resume the background music too after SCRecorder disappear.