Skip to content

Commit

Permalink
Adjust AVAudioSession CategoryOptions (include .mixWithOthers)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie authored Jul 13, 2023
1 parent fcc124d commit a4f4c01
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Sources/LiveKit/Track/AudioManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,19 @@ public class AudioManager: Loggable {

// prepare config
let configuration = RTCAudioSessionConfiguration.webRTC()
var categoryOptions: AVAudioSession.CategoryOptions = []

if newState.trackState == .remoteOnly && newState.preferSpeakerOutput {
/* .playback */
configuration.category = AVAudioSession.Category.playback.rawValue
configuration.mode = AVAudioSession.Mode.spokenAudio.rawValue
configuration.categoryOptions = [
.mixWithOthers
]

} else if [.localOnly, .localAndRemote].contains(newState.trackState) ||
(newState.trackState == .remoteOnly && !newState.preferSpeakerOutput) {

/* .playAndRecord */
configuration.category = AVAudioSession.Category.playAndRecord.rawValue

if newState.preferSpeakerOutput {
Expand All @@ -159,15 +163,20 @@ public class AudioManager: Loggable {
configuration.mode = AVAudioSession.Mode.voiceChat.rawValue
}

categoryOptions = [.allowBluetooth, .allowBluetoothA2DP]
configuration.categoryOptions = [
.mixWithOthers,
.allowBluetooth,
.allowBluetoothA2DP,
.allowAirPlay
]

} else {
/* .soloAmbient */
configuration.category = AVAudioSession.Category.soloAmbient.rawValue
configuration.mode = AVAudioSession.Mode.default.rawValue
configuration.categoryOptions = []
}

configuration.categoryOptions = categoryOptions

var setActive: Bool?

if newState.trackState != .none, oldState.trackState == .none {
Expand Down

0 comments on commit a4f4c01

Please sign in to comment.