- request audio focus for outbound and incoming calls
This commit is contained in:
+2
-2
@@ -8,8 +8,8 @@ android {
|
|||||||
applicationId = 'com.tutpro.baresip'
|
applicationId = 'com.tutpro.baresip'
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode = 15
|
versionCode = 16
|
||||||
versionName = '2.2.2'
|
versionName = '2.3'
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
cFlags '-DHAVE_INTTYPES_H'
|
cFlags '-DHAVE_INTTYPES_H'
|
||||||
|
|||||||
@@ -279,7 +279,6 @@ class BaresipService: Service() {
|
|||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
}
|
}
|
||||||
"call ringing" -> {
|
"call ringing" -> {
|
||||||
return
|
|
||||||
}
|
}
|
||||||
"call incoming" -> {
|
"call incoming" -> {
|
||||||
if (!Utils.isVisible()) {
|
if (!Utils.isVisible()) {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import android.content.IntentFilter
|
|||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
|
import android.media.AudioManager.STREAM_RING
|
||||||
|
import android.media.AudioManager.STREAM_VOICE_CALL
|
||||||
import android.media.Ringtone
|
import android.media.Ringtone
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
import android.support.v4.content.LocalBroadcastManager
|
import android.support.v4.content.LocalBroadcastManager
|
||||||
@@ -360,7 +362,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val ev = event.split(",")
|
val ev = event.split(",")
|
||||||
Log.d("Baresip", "Handling service event ${ev[0]} for $uap")
|
Log.d("Baresip", "Handling service event '${ev[0]}' for $uap")
|
||||||
val aor = ua.account.aor
|
val aor = ua.account.aor
|
||||||
val acc = ua.account
|
val acc = ua.account
|
||||||
for (account_index in uas.indices) {
|
for (account_index in uas.indices) {
|
||||||
@@ -373,6 +375,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
"registered", "registering failed", "unregistering" -> {
|
"registered", "registering failed", "unregistering" -> {
|
||||||
uaAdapter.notifyDataSetChanged()
|
uaAdapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
"call ringing" -> {
|
||||||
|
requestAudioFocus(STREAM_VOICE_CALL)
|
||||||
|
}
|
||||||
"call incoming" -> {
|
"call incoming" -> {
|
||||||
val callp = params[1]
|
val callp = params[1]
|
||||||
if (ContextCompat.checkSelfPermission(applicationContext,
|
if (ContextCompat.checkSelfPermission(applicationContext,
|
||||||
@@ -467,6 +472,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if (rt.isPlaying) rt.stop()
|
if (rt.isPlaying) rt.stop()
|
||||||
}
|
}
|
||||||
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
|
requestAudioFocus(STREAM_VOICE_CALL)
|
||||||
am.isSpeakerphoneOn = false
|
am.isSpeakerphoneOn = false
|
||||||
// am.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
|
// am.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
|
||||||
// (am.getStreamMaxVolume(STREAM_VOICE_CALL) / 2) + 1,
|
// (am.getStreamMaxVolume(STREAM_VOICE_CALL) / 2) + 1,
|
||||||
@@ -627,6 +633,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
speakerIcon.setBackgroundColor(ContextCompat.getColor(applicationContext,
|
speakerIcon.setBackgroundColor(ContextCompat.getColor(applicationContext,
|
||||||
R.color.colorPrimary))
|
R.color.colorPrimary))
|
||||||
}
|
}
|
||||||
|
if (audioFocused) {
|
||||||
|
am.abandonAudioFocus(null)
|
||||||
|
audioFocused = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"message" -> {
|
"message" -> {
|
||||||
val peer_uri = params[1]
|
val peer_uri = params[1]
|
||||||
@@ -657,7 +667,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
setIntent(intent)
|
setIntent(intent)
|
||||||
val action = intent.getStringExtra("action")
|
val action = intent.getStringExtra("action")
|
||||||
Log.d("Baresip", "Got onNewIntent action $action")
|
Log.d("Baresip", "Got onNewIntent action '$action'")
|
||||||
when (action) {
|
when (action) {
|
||||||
"call" -> {
|
"call" -> {
|
||||||
if (!calls.isEmpty()) {
|
if (!calls.isEmpty()) {
|
||||||
@@ -1103,8 +1113,22 @@ class MainActivity : AppCompatActivity() {
|
|||||||
button.setImageResource(R.drawable.play)
|
button.setImageResource(R.drawable.play)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun requestAudioFocus(stream: Int) {
|
||||||
|
if (!audioFocused) {
|
||||||
|
val res = am.requestAudioFocus(null, stream, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE)
|
||||||
|
if (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
|
||||||
|
Log.d("Baresip", "Audio focus granted")
|
||||||
|
audioFocused = true
|
||||||
|
} else {
|
||||||
|
Log.d("Baresip", "Audio focus denied")
|
||||||
|
audioFocused = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun startRinging() {
|
private fun startRinging() {
|
||||||
am.mode = AudioManager.MODE_RINGTONE
|
am.mode = AudioManager.MODE_RINGTONE
|
||||||
|
requestAudioFocus(STREAM_RING)
|
||||||
rt.play()
|
rt.play()
|
||||||
rtTimer = Timer()
|
rtTimer = Timer()
|
||||||
rtTimer!!.scheduleAtFixedRate(object : TimerTask() {
|
rtTimer!!.scheduleAtFixedRate(object : TimerTask() {
|
||||||
@@ -1142,6 +1166,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
var history: ArrayList<CallHistory> = ArrayList()
|
var history: ArrayList<CallHistory> = ArrayList()
|
||||||
internal var calls = ArrayList<Call>()
|
internal var calls = ArrayList<Call>()
|
||||||
internal var messages = ArrayList<Message>()
|
internal var messages = ArrayList<Message>()
|
||||||
|
internal var audioFocused = false
|
||||||
var filesPath = ""
|
var filesPath = ""
|
||||||
var visible = true
|
var visible = true
|
||||||
var makeCall = ""
|
var makeCall = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user