CameraEngine icon indicating copy to clipboard operation
CameraEngine copied to clipboard

how to play sound with preview layer?

Open patthehuman opened this issue 8 years ago • 2 comments

if i have an app open thats already playing sound how do i make it so the preview layer doesnt stop?

patthehuman avatar Apr 21 '16 01:04 patthehuman

Just leaving this for everyone as I got it to work..

Call this right before setupSession()

func setupBackgroundAudioPreference() {
        do{
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord,
                                                            with: [.defaultToSpeaker, .mixWithOthers ])
            try AVAudioSession.sharedInstance().setActive(true)
            session.automaticallyConfiguresApplicationAudioSession = false
        }
        catch {
            print("Could not set audio preference..")
            
        }
    }
}

ghost avatar Mar 09 '17 10:03 ghost

@danieldelouya any other recommendation? It's strangely working for me the first time I open the camera but not the second one.

marcosgriselli avatar Mar 16 '17 21:03 marcosgriselli