Audio improvements:
- do not use MODE_NORMAL in order to avoid delay when switching to MODE_IN_COMMUNICATION - use volume control stream STREAM_VOICE_CALL instead of STREAM_MUSIC
This commit is contained in:
@@ -621,8 +621,6 @@ class BaresipService: Service() {
|
|||||||
call.hasHistory = true
|
call.hasHistory = true
|
||||||
}
|
}
|
||||||
stopRinging()
|
stopRinging()
|
||||||
if (am.mode != AudioManager.MODE_IN_COMMUNICATION)
|
|
||||||
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
|
||||||
requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION)
|
requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION)
|
||||||
setCallVolume()
|
setCallVolume()
|
||||||
if (!Utils.isVisible())
|
if (!Utils.isVisible())
|
||||||
@@ -704,8 +702,6 @@ class BaresipService: Service() {
|
|||||||
call.remove()
|
call.remove()
|
||||||
if (Call.calls().size == 0) {
|
if (Call.calls().size == 0) {
|
||||||
resetCallVolume()
|
resetCallVolume()
|
||||||
if (am.mode != AudioManager.MODE_NORMAL)
|
|
||||||
am.mode = AudioManager.MODE_NORMAL
|
|
||||||
am.isSpeakerphoneOn = false
|
am.isSpeakerphoneOn = false
|
||||||
if (am.isBluetoothScoOn) {
|
if (am.isBluetoothScoOn) {
|
||||||
Log.d(TAG, "Stopping Bluetooth SCO")
|
Log.d(TAG, "Stopping Bluetooth SCO")
|
||||||
@@ -1049,12 +1045,13 @@ class BaresipService: Service() {
|
|||||||
rtTimer = null
|
rtTimer = null
|
||||||
}
|
}
|
||||||
rt.stop()
|
rt.stop()
|
||||||
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setCallVolume() {
|
private fun setCallVolume() {
|
||||||
if ((callVolume != 0) && (origVolumes.contentEquals(arrayOf(-1, -1, -1, -1)))) {
|
if ((callVolume != 0) && (origVolumes.contentEquals(arrayOf(-1, -1, -1, -1)))) {
|
||||||
for (streamType in listOf(AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_MUSIC)) {
|
for (streamType in listOf(AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_RING)) {
|
||||||
origVolumes[streamType] = am.getStreamVolume(streamType)
|
origVolumes[streamType] = am.getStreamVolume(streamType)
|
||||||
am.setStreamVolume(streamType,
|
am.setStreamVolume(streamType,
|
||||||
(callVolume * 0.1 * am.getStreamMaxVolume(streamType)).roundToInt(),
|
(callVolume * 0.1 * am.getStreamMaxVolume(streamType)).roundToInt(),
|
||||||
@@ -1066,7 +1063,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun resetCallVolume() {
|
private fun resetCallVolume() {
|
||||||
for (streamType in listOf(AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_MUSIC)) {
|
for (streamType in listOf(AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_RING)) {
|
||||||
if (origVolumes[streamType] != -1) {
|
if (origVolumes[streamType] != -1) {
|
||||||
am.setStreamVolume(streamType, origVolumes[streamType], 0)
|
am.setStreamVolume(streamType, origVolumes[streamType], 0)
|
||||||
Log.d(TAG, "Reset volume of stream type $streamType to " +
|
Log.d(TAG, "Reset volume of stream type $streamType to " +
|
||||||
|
|||||||
@@ -311,10 +311,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
String.format(getString(R.string.invalid_sip_uri), uri))
|
String.format(getString(R.string.invalid_sip_uri), uri))
|
||||||
} else {
|
} else {
|
||||||
callUri.isFocusable = false
|
callUri.isFocusable = false
|
||||||
if (am.mode != AudioManager.MODE_IN_COMMUNICATION)
|
|
||||||
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
|
||||||
if (!call(ua, uri)) {
|
if (!call(ua, uri)) {
|
||||||
am.mode = AudioManager.MODE_NORMAL
|
|
||||||
callButton.visibility = View.VISIBLE
|
callButton.visibility = View.VISIBLE
|
||||||
callButton.isEnabled = true
|
callButton.isEnabled = true
|
||||||
hangupButton.visibility = View.INVISIBLE
|
hangupButton.visibility = View.INVISIBLE
|
||||||
@@ -629,6 +626,13 @@ class MainActivity : AppCompatActivity() {
|
|||||||
delegate.applyDayNight()
|
delegate.applyDayNight()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (am.mode == AudioManager.MODE_RINGTONE) {
|
||||||
|
volumeControlStream = AudioManager.STREAM_RING
|
||||||
|
} else {
|
||||||
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
|
volumeControlStream = AudioManager.STREAM_VOICE_CALL
|
||||||
|
}
|
||||||
|
|
||||||
} // OnCreate
|
} // OnCreate
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
@@ -917,7 +921,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Toast.LENGTH_LONG).show()
|
Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
"call ringing", "call progress" -> {
|
"call ringing", "call progress" -> {
|
||||||
volumeControlStream = AudioManager.STREAM_MUSIC
|
volumeControlStream = AudioManager.STREAM_VOICE_CALL
|
||||||
}
|
}
|
||||||
"call rejected" -> {
|
"call rejected" -> {
|
||||||
if (aor == aorSpinner.tag) {
|
if (aor == aorSpinner.tag) {
|
||||||
@@ -944,7 +948,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"call established" -> {
|
"call established" -> {
|
||||||
volumeControlStream = AudioManager.STREAM_MUSIC
|
volumeControlStream = AudioManager.STREAM_VOICE_CALL
|
||||||
if (aor == aorSpinner.tag) {
|
if (aor == aorSpinner.tag) {
|
||||||
dtmf.setText("")
|
dtmf.setText("")
|
||||||
dtmf.hint = getString(R.string.dtmf)
|
dtmf.hint = getString(R.string.dtmf)
|
||||||
@@ -1068,7 +1072,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
callsButton.setImageResource(R.drawable.calls_missed)
|
callsButton.setImageResource(R.drawable.calls_missed)
|
||||||
}
|
}
|
||||||
if (speakerIcon != null) speakerIcon!!.setIcon(R.drawable.speaker_off)
|
if (speakerIcon != null) speakerIcon!!.setIcon(R.drawable.speaker_off)
|
||||||
volumeControlStream = AudioManager.STREAM_MUSIC
|
volumeControlStream = AudioManager.STREAM_VOICE_CALL
|
||||||
val param = ev[1].trim()
|
val param = ev[1].trim()
|
||||||
if ((param != "") && (Call.uaCalls(ua, "").size == 0)) {
|
if ((param != "") && (Call.uaCalls(ua, "").size == 0)) {
|
||||||
if (param[0].isDigit())
|
if (param[0].isDigit())
|
||||||
@@ -1606,7 +1610,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
dtmf.visibility = View.INVISIBLE
|
dtmf.visibility = View.INVISIBLE
|
||||||
dialpadButton.isEnabled = true
|
dialpadButton.isEnabled = true
|
||||||
infoButton.visibility = View.INVISIBLE
|
infoButton.visibility = View.INVISIBLE
|
||||||
volumeControlStream = AudioManager.STREAM_MUSIC
|
volumeControlStream = AudioManager.STREAM_VOICE_CALL
|
||||||
} else {
|
} else {
|
||||||
val call = Call.uaCalls(ua, "")[0]
|
val call = Call.uaCalls(ua, "")[0]
|
||||||
callUri.isFocusable = false
|
callUri.isFocusable = false
|
||||||
@@ -1627,7 +1631,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
dtmf.visibility = View.INVISIBLE
|
dtmf.visibility = View.INVISIBLE
|
||||||
dialpadButton.isEnabled = false
|
dialpadButton.isEnabled = false
|
||||||
infoButton.visibility = View.INVISIBLE
|
infoButton.visibility = View.INVISIBLE
|
||||||
volumeControlStream = AudioManager.STREAM_MUSIC
|
volumeControlStream = AudioManager.STREAM_VOICE_CALL
|
||||||
}
|
}
|
||||||
"incoming" -> {
|
"incoming" -> {
|
||||||
callTitle.text = getString(R.string.incoming_call_from_dots)
|
callTitle.text = getString(R.string.incoming_call_from_dots)
|
||||||
@@ -1696,7 +1700,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
dialpadButton.isEnabled = false
|
dialpadButton.isEnabled = false
|
||||||
infoButton.visibility = View.VISIBLE
|
infoButton.visibility = View.VISIBLE
|
||||||
infoButton.isEnabled = true
|
infoButton.isEnabled = true
|
||||||
volumeControlStream = AudioManager.STREAM_MUSIC
|
volumeControlStream = AudioManager.STREAM_VOICE_CALL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user