More media player related enhancements

This commit is contained in:
Juha Heinanen
2021-11-01 10:13:59 +02:00
parent af6bdc5027
commit 67f153a74c
2 changed files with 22 additions and 12 deletions

View File

@ -160,6 +160,7 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
char event_buf[256];
char ua_buf[32];
char call_buf[32];
enum sdp_dir ardir;
int len;
LOGD("ua event (%s) %s\n", uag_event_str(ev), prm);
@ -193,7 +194,8 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
len = re_snprintf(event_buf, sizeof event_buf, "%s", "call ringing");
break;
case UA_EVENT_CALL_PROGRESS:
len = re_snprintf(event_buf, sizeof event_buf, "%s", "call progress");
ardir = sdp_media_rdir(stream_sdpmedia(audio_strm(call_audio(call))));
len = re_snprintf(event_buf, sizeof event_buf, "%s", "call progress,%d", ardir);
break;
case UA_EVENT_CALL_ESTABLISHED:
len = re_snprintf(event_buf, sizeof event_buf, "%s", "call established");

View File

@ -518,18 +518,20 @@ class BaresipService: Service() {
if (!Utils.isVisible())
return
}
"call progress", "call ringing" -> {
"call ringing" -> {
am.mode = AudioManager.MODE_IN_COMMUNICATION
requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION,
AudioAttributes.CONTENT_TYPE_SPEECH)
setCallVolume()
if (mediaPlayer == null ) {
mediaPlayer = MediaPlayer.create(this, R.raw.ringback)
mediaPlayer!!.isLooping = true
mediaPlayer!!.start()
}
playRingBack()
return
}
"call progress" -> {
if (ev[1] != "0")
stopMediaPlayer()
else
playRingBack()
}
"call incoming" -> {
val peerUri = Api.call_peeruri(callp)
if ((Call.calls().size > 0) ||
@ -538,7 +540,6 @@ class BaresipService: Service() {
Manifest.permission.RECORD_AUDIO)) {
Log.d(TAG, "Auto-rejecting incoming call $uap/$callp/$peerUri")
Api.ua_hangup(uap, callp, 486, "Busy Here")
playNTimes(R.raw.callwaiting, 1)
if (ua.account.callHistory) {
CallHistory.add(CallHistory(aor, peerUri, "in", false))
CallHistory.save()
@ -560,8 +561,6 @@ class BaresipService: Service() {
startRinging()
}
} else {
val mediaPlayer = MediaPlayer.create(this, R.raw.autoanswer)
mediaPlayer.start()
val newIntent = Intent(this, MainActivity::class.java)
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
Intent.FLAG_ACTIVITY_NEW_TASK
@ -630,6 +629,7 @@ class BaresipService: Service() {
}
}
"call outgoing" -> {
stopMediaPlayer()
am.mode = AudioManager.MODE_IN_COMMUNICATION
requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION,
AudioAttributes.CONTENT_TYPE_SPEECH)
@ -1146,14 +1146,22 @@ class BaresipService: Service() {
rt.stop()
}
private fun playRingBack() {
if (mediaPlayer == null) {
mediaPlayer = MediaPlayer.create(this, R.raw.ringback)
mediaPlayer?.isLooping = true
mediaPlayer?.start()
}
}
private fun playNTimes(raw: Int, count: Int) {
if (mediaPlayer == null ) {
mediaPlayer = MediaPlayer.create(this, raw)
mediaPlayer!!.setOnCompletionListener {
mediaPlayer?.setOnCompletionListener {
stopMediaPlayer()
if (count > 1) playNTimes(raw, count - 1)
}
mediaPlayer!!.start()
mediaPlayer?.start()
}
}