This commit is contained in:
Horis
2026-02-01 10:32:26 +08:00
parent 40647f528a
commit f49043ceaa
2 changed files with 18 additions and 12 deletions
@@ -1,7 +1,6 @@
package io.legado.app.ui.book.audio
import android.annotation.SuppressLint
import android.icu.text.SimpleDateFormat
import android.os.Build
import android.os.Bundle
import android.view.Gravity
@@ -44,6 +43,7 @@ import io.legado.app.utils.sendToClip
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.startActivity
import io.legado.app.utils.startActivityForBook
import io.legado.app.utils.toDurationTime
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
import kotlinx.coroutines.Dispatchers.IO
@@ -67,13 +67,6 @@ class AudioPlayActivity :
private var adjustProgress = false
private var playMode = AudioPlay.PlayMode.LIST_END_STOP
private val progressTimeFormat by lazy {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
SimpleDateFormat("mm:ss", Locale.getDefault())
} else {
java.text.SimpleDateFormat("mm:ss", Locale.getDefault())
}
}
private val tocActivityResult = registerForActivityResult(TocActivityResult()) {
it?.let {
if (it.first != AudioPlay.book?.durChapterIndex
@@ -164,7 +157,7 @@ class AudioPlayActivity :
}
binding.playerProgress.setOnSeekBarChangeListener(object : SeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
binding.tvDurTime.text = progressTimeFormat.format(progress.toLong())
binding.tvDurTime.text = progress.toDurationTime()
}
override fun onStartTrackingTouch(seekBar: SeekBar) {
@@ -291,11 +284,11 @@ class AudioPlayActivity :
}
observeEventSticky<Int>(EventBus.AUDIO_SIZE) {
binding.playerProgress.max = it
binding.tvAllTime.text = progressTimeFormat.format(it.toLong())
binding.tvAllTime.text = it.toDurationTime()
}
observeEventSticky<Int>(EventBus.AUDIO_PROGRESS) {
if (!adjustProgress) binding.playerProgress.progress = it
binding.tvDurTime.text = progressTimeFormat.format(it.toLong())
binding.tvDurTime.text = it.toDurationTime()
}
observeEventSticky<Int>(EventBus.AUDIO_BUFFER_PROGRESS) {
binding.playerProgress.secondaryProgress = it
@@ -37,3 +37,16 @@ fun Long.toTimeAgo(): String {
}
return start + end
}
fun Int.toDurationTime(): String {
val totalSeconds = this / 1000
val hours = totalSeconds / 3600
val minutes = (totalSeconds % 3600) / 60
val seconds = totalSeconds % 60
return if (hours > 0) {
"%d:%02d:%02d".format(hours, minutes, seconds)
} else {
"%02d:%02d".format(minutes, seconds)
}
}