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

Video recording with background music playing, not paused #331

Open toddoh opened 8 years ago

toddoh commented 8 years ago

I found multiple posts on here that disabling automaticallyConfiguresApplicationAudioSession (to NO) and adding AVAudioSession codes to AppDelegate would let SCRecorder to not pause background music. (https://github.com/rFlex/SCRecorder/issues/194#issuecomment-146440130)

However, when I disable that option, recorder stops working for video recording preset/mode, only photo mode works properly. I see that Snapchat and Vine supports video recording even with bg music playing.

Is there any solution for this?

aprato commented 8 years ago

The safest way I've found is to:

let sess = AVAudioSession.sharedInstance()
do {
            try sess.setActive(false)
            try sess.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: [ .MixWithOthers, .DefaultToSpeaker ])
            try sess.setMode(AVAudioSessionModeVideoRecording)
            try sess.setActive(true)
        } catch let error as NSError {
            print("shared audio session error: \(error.localizedDescription)")
        }

before you set the recorder's session and call startRunning

toddoh commented 8 years ago

Thanks man!