声音播放
This commit is contained in:
parent
5f09d0646f
commit
7376b902e9
|
|
@ -537,7 +537,7 @@ class AndroidInterface(private val activity: MainActivity) {
|
|||
fun playAlert(count: Int, volume: Float) {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
try {
|
||||
stopAlert()
|
||||
realStopAlert()
|
||||
alertPlayCount = 0
|
||||
alertPlayer = android.media.MediaPlayer.create(activity, R.raw.pull_alert).apply {
|
||||
setVolume(volume, volume)
|
||||
|
|
@ -549,10 +549,10 @@ class AndroidInterface(private val activity: MainActivity) {
|
|||
it.start()
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("AlertPlayer").e(e, "Error repeating alert play")
|
||||
stopAlert()
|
||||
realStopAlert()
|
||||
}
|
||||
} else {
|
||||
stopAlert()
|
||||
realStopAlert()
|
||||
}
|
||||
}
|
||||
start()
|
||||
|
|
@ -565,7 +565,16 @@ class AndroidInterface(private val activity: MainActivity) {
|
|||
}
|
||||
|
||||
fun stopAlert() {
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
realStopAlert()
|
||||
} else {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
realStopAlert()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun realStopAlert() {
|
||||
try {
|
||||
alertPlayer?.let { player ->
|
||||
if (player.isPlaying) {
|
||||
|
|
@ -580,4 +589,3 @@ class AndroidInterface(private val activity: MainActivity) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue