Simplified audio management
This commit is contained in:
@ -65,7 +65,6 @@ import androidx.core.content.ContextCompat
|
|||||||
import androidx.core.graphics.drawable.IconCompat
|
import androidx.core.graphics.drawable.IconCompat
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.media.AudioFocusRequestCompat
|
|
||||||
import com.tutpro.baresip.Utils.toCircle
|
import com.tutpro.baresip.Utils.toCircle
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -2068,7 +2067,6 @@ class BaresipService: Service() {
|
|||||||
var dnsServers = listOf<InetAddress>()
|
var dnsServers = listOf<InetAddress>()
|
||||||
// <aor, password> of those accounts that have auth username without auth password
|
// <aor, password> of those accounts that have auth username without auth password
|
||||||
val aorPasswords = mutableMapOf<String, String>()
|
val aorPasswords = mutableMapOf<String, String>()
|
||||||
var audioFocusRequest: AudioFocusRequestCompat? = null
|
|
||||||
var aecAvailable = false
|
var aecAvailable = false
|
||||||
private var aec: AcousticEchoCanceler? = null
|
private var aec: AcousticEchoCanceler? = null
|
||||||
var agcAvailable = false
|
var agcAvailable = false
|
||||||
|
|||||||
@ -859,14 +859,6 @@ object Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isSpeakerPhoneOn(am: AudioManager): Boolean {
|
|
||||||
return if (Build.VERSION.SDK_INT >= 31)
|
|
||||||
am.communicationDevice!!.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER
|
|
||||||
else
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
am.isSpeakerphoneOn
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setSpeakerPhone(executor: Executor, am: AudioManager, enable: Boolean) {
|
private fun setSpeakerPhone(executor: Executor, am: AudioManager, enable: Boolean) {
|
||||||
if (Build.VERSION.SDK_INT >= 31) {
|
if (Build.VERSION.SDK_INT >= 31) {
|
||||||
val current = am.communicationDevice!!.type
|
val current = am.communicationDevice!!.type
|
||||||
@ -895,7 +887,7 @@ object Utils {
|
|||||||
Log.d(TAG, "Setting com device to TYPE_BUILTIN_EARPIECE")
|
Log.d(TAG, "Setting com device to TYPE_BUILTIN_EARPIECE")
|
||||||
if (!am.setCommunicationDevice(speakerDevice))
|
if (!am.setCommunicationDevice(speakerDevice))
|
||||||
Log.e(TAG, "Could not set com device")
|
Log.e(TAG, "Could not set com device")
|
||||||
if (BaresipService.audioFocusRequest != null && am.mode == AudioManager.MODE_NORMAL) {
|
if (Call.inCall() && am.mode == AudioManager.MODE_NORMAL) {
|
||||||
Log.d(TAG, "Setting mode to communication")
|
Log.d(TAG, "Setting mode to communication")
|
||||||
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
}
|
}
|
||||||
@ -945,18 +937,6 @@ object Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.S)
|
|
||||||
fun setCommunicationDevice(am: AudioManager, type: Int) {
|
|
||||||
val current = am.communicationDevice!!.type
|
|
||||||
Log.d(TAG, "Current com dev/mode $current/${am.mode}")
|
|
||||||
for (device in am.availableCommunicationDevices)
|
|
||||||
if (device.type == type) {
|
|
||||||
am.setCommunicationDevice(device)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
Log.d(TAG, "New com dev/mode ${am.communicationDevice!!.type}/${am.mode}")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun clearCommunicationDevice(am: AudioManager) {
|
private fun clearCommunicationDevice(am: AudioManager) {
|
||||||
if (Build.VERSION.SDK_INT >= 31) {
|
if (Build.VERSION.SDK_INT >= 31) {
|
||||||
am.clearCommunicationDevice()
|
am.clearCommunicationDevice()
|
||||||
|
|||||||
Reference in New Issue
Block a user