feat: implement MediaPlayer voice alert and confirm-to-mute logic
This commit is contained in:
parent
59f48520a2
commit
d7e9b29513
|
|
@ -26,6 +26,8 @@ class TempCallActivity : AppCompatActivity() {
|
||||||
private val MIN_SPEAK_DURATION = 200L
|
private val MIN_SPEAK_DURATION = 200L
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
private var pulseAnimator: ObjectAnimator? = null
|
private var pulseAnimator: ObjectAnimator? = null
|
||||||
|
private var alertPlayer: android.media.MediaPlayer? = null
|
||||||
|
private var alertPlayCount = 0
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@Volatile
|
@Volatile
|
||||||
|
|
@ -102,6 +104,7 @@ class TempCallActivity : AppCompatActivity() {
|
||||||
setupPttButton()
|
setupPttButton()
|
||||||
setupHangupButton()
|
setupHangupButton()
|
||||||
startPulseAnimation()
|
startPulseAnimation()
|
||||||
|
startVoiceAlert()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
|
@ -119,6 +122,7 @@ class TempCallActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
MainActivity.executeJs("onTempCallStateChanged('" + if (isMinimized) "minimized" else "destroyed" + "')")
|
MainActivity.executeJs("onTempCallStateChanged('" + if (isMinimized) "minimized" else "destroyed" + "')")
|
||||||
}
|
}
|
||||||
|
stopVoiceAlert()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拦截返回键
|
// 拦截返回键
|
||||||
|
|
@ -280,4 +284,51 @@ class TempCallActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun startVoiceAlert() {
|
||||||
|
try {
|
||||||
|
findViewById<Button>(R.id.btn_confirm_alert)?.apply {
|
||||||
|
visibility = View.VISIBLE
|
||||||
|
setOnClickListener {
|
||||||
|
stopVoiceAlert()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alertPlayCount = 0
|
||||||
|
alertPlayer = android.media.MediaPlayer.create(this, R.raw.pull_alert).apply {
|
||||||
|
setOnCompletionListener {
|
||||||
|
alertPlayCount++
|
||||||
|
if (alertPlayCount < 3) {
|
||||||
|
try {
|
||||||
|
it.start()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
timber.log.Timber.tag("TempCallAlert").e(e, "Error repeating voice play")
|
||||||
|
stopVoiceAlert()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stopVoiceAlert()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
timber.log.Timber.tag("TempCallAlert").e(e, "Error initializing MediaPlayer")
|
||||||
|
findViewById<Button>(R.id.btn_confirm_alert)?.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopVoiceAlert() {
|
||||||
|
try {
|
||||||
|
findViewById<Button>(R.id.btn_confirm_alert)?.visibility = View.GONE
|
||||||
|
alertPlayer?.let { player ->
|
||||||
|
if (player.isPlaying) {
|
||||||
|
player.stop()
|
||||||
|
}
|
||||||
|
player.release()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
timber.log.Timber.tag("TempCallAlert").e(e, "Error stopping MediaPlayer")
|
||||||
|
} finally {
|
||||||
|
alertPlayer = null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue