import AVFoundation
import ComposableArchitecture

/**
 Exclusively functions to set the AVAudioSession to mix with others.
 */

public struct WelcomeLoopingVideoPlayerClient {
    public var setAVAudioSessionToMixWithOthers: () -> Void
}

extension WelcomeLoopingVideoPlayerClient: DependencyKey {
    public static let liveValue: Self = Self(
        setAVAudioSessionToMixWithOthers: {
            let audioSession = AVAudioSession.sharedInstance()
            try? audioSession.setCategory(.playback, options: .mixWithOthers)
            try? audioSession.setActive(false)
        }
    )
}
