More media player related enhancements
This commit is contained in:
@@ -160,6 +160,7 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
|
|||||||
char event_buf[256];
|
char event_buf[256];
|
||||||
char ua_buf[32];
|
char ua_buf[32];
|
||||||
char call_buf[32];
|
char call_buf[32];
|
||||||
|
enum sdp_dir ardir;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
LOGD("ua event (%s) %s\n", uag_event_str(ev), prm);
|
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");
|
len = re_snprintf(event_buf, sizeof event_buf, "%s", "call ringing");
|
||||||
break;
|
break;
|
||||||
case UA_EVENT_CALL_PROGRESS:
|
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;
|
break;
|
||||||
case UA_EVENT_CALL_ESTABLISHED:
|
case UA_EVENT_CALL_ESTABLISHED:
|
||||||
len = re_snprintf(event_buf, sizeof event_buf, "%s", "call established");
|
len = re_snprintf(event_buf, sizeof event_buf, "%s", "call established");
|
||||||
|
|||||||
@@ -518,18 +518,20 @@ class BaresipService: Service() {
|
|||||||
if (!Utils.isVisible())
|
if (!Utils.isVisible())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
"call progress", "call ringing" -> {
|
"call ringing" -> {
|
||||||
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION,
|
requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION,
|
||||||
AudioAttributes.CONTENT_TYPE_SPEECH)
|
AudioAttributes.CONTENT_TYPE_SPEECH)
|
||||||
setCallVolume()
|
setCallVolume()
|
||||||
if (mediaPlayer == null ) {
|
playRingBack()
|
||||||
mediaPlayer = MediaPlayer.create(this, R.raw.ringback)
|
|
||||||
mediaPlayer!!.isLooping = true
|
|
||||||
mediaPlayer!!.start()
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
"call progress" -> {
|
||||||
|
if (ev[1] != "0")
|
||||||
|
stopMediaPlayer()
|
||||||
|
else
|
||||||
|
playRingBack()
|
||||||
|
}
|
||||||
"call incoming" -> {
|
"call incoming" -> {
|
||||||
val peerUri = Api.call_peeruri(callp)
|
val peerUri = Api.call_peeruri(callp)
|
||||||
if ((Call.calls().size > 0) ||
|
if ((Call.calls().size > 0) ||
|
||||||
@@ -538,7 +540,6 @@ class BaresipService: Service() {
|
|||||||
Manifest.permission.RECORD_AUDIO)) {
|
Manifest.permission.RECORD_AUDIO)) {
|
||||||
Log.d(TAG, "Auto-rejecting incoming call $uap/$callp/$peerUri")
|
Log.d(TAG, "Auto-rejecting incoming call $uap/$callp/$peerUri")
|
||||||
Api.ua_hangup(uap, callp, 486, "Busy Here")
|
Api.ua_hangup(uap, callp, 486, "Busy Here")
|
||||||
playNTimes(R.raw.callwaiting, 1)
|
|
||||||
if (ua.account.callHistory) {
|
if (ua.account.callHistory) {
|
||||||
CallHistory.add(CallHistory(aor, peerUri, "in", false))
|
CallHistory.add(CallHistory(aor, peerUri, "in", false))
|
||||||
CallHistory.save()
|
CallHistory.save()
|
||||||
@@ -560,8 +561,6 @@ class BaresipService: Service() {
|
|||||||
startRinging()
|
startRinging()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val mediaPlayer = MediaPlayer.create(this, R.raw.autoanswer)
|
|
||||||
mediaPlayer.start()
|
|
||||||
val newIntent = Intent(this, MainActivity::class.java)
|
val newIntent = Intent(this, MainActivity::class.java)
|
||||||
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
@@ -630,6 +629,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"call outgoing" -> {
|
"call outgoing" -> {
|
||||||
|
stopMediaPlayer()
|
||||||
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION,
|
requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION,
|
||||||
AudioAttributes.CONTENT_TYPE_SPEECH)
|
AudioAttributes.CONTENT_TYPE_SPEECH)
|
||||||
@@ -1146,14 +1146,22 @@ class BaresipService: Service() {
|
|||||||
rt.stop()
|
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) {
|
private fun playNTimes(raw: Int, count: Int) {
|
||||||
if (mediaPlayer == null ) {
|
if (mediaPlayer == null ) {
|
||||||
mediaPlayer = MediaPlayer.create(this, raw)
|
mediaPlayer = MediaPlayer.create(this, raw)
|
||||||
mediaPlayer!!.setOnCompletionListener {
|
mediaPlayer?.setOnCompletionListener {
|
||||||
stopMediaPlayer()
|
stopMediaPlayer()
|
||||||
if (count > 1) playNTimes(raw, count - 1)
|
if (count > 1) playNTimes(raw, count - 1)
|
||||||
}
|
}
|
||||||
mediaPlayer!!.start()
|
mediaPlayer?.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user