feat: 优化

pull/238/head
gedoor 5 years ago
parent 9e074a7990
commit 1d292eb97a
  1. 1
      app/src/main/assets/updateLog.md
  2. 22
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -5,6 +5,7 @@
**2020/06/03** **2020/06/03**
* zh-TW translation by david082321 * zh-TW translation by david082321
* 修复音频播放时播放速度调节会再下一章失效的bug
**2020/05/31** **2020/05/31**
* 更新到android studio 4.0 * 更新到android studio 4.0

@ -63,6 +63,7 @@ class AudioPlayService : BaseService(),
private val dsRunnable: Runnable = Runnable { doDs() } private val dsRunnable: Runnable = Runnable { doDs() }
private var mpRunnable: Runnable = Runnable { upPlayProgress() } private var mpRunnable: Runnable = Runnable { upPlayProgress() }
private var bookChapter: BookChapter? = null private var bookChapter: BookChapter? = null
private var playSpeed: Float = 1f
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
@ -95,7 +96,12 @@ class AudioPlayService : BaseService(),
IntentAction.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f)) IntentAction.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f))
IntentAction.addTimer -> addTimer() IntentAction.addTimer -> addTimer()
IntentAction.setTimer -> setTimer(intent.getIntExtra("minute", 0)) IntentAction.setTimer -> setTimer(intent.getIntExtra("minute", 0))
IntentAction.adjustProgress -> adjustProgress(intent.getIntExtra("position", position)) IntentAction.adjustProgress -> adjustProgress(
intent.getIntExtra(
"position",
position
)
)
else -> stopSelf() else -> stopSelf()
} }
} }
@ -174,12 +180,12 @@ class AudioPlayService : BaseService(),
private fun upSpeed(adjust: Float) { private fun upSpeed(adjust: Float) {
kotlin.runCatching { kotlin.runCatching {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
with(mediaPlayer) { playSpeed += adjust
if (isPlaying) { if (mediaPlayer.isPlaying) {
playbackParams = playbackParams.apply { speed += adjust } mediaPlayer.playbackParams =
} mediaPlayer.playbackParams.apply { speed = playSpeed }
postEvent(EventBus.AUDIO_SPEED, playbackParams.speed)
} }
postEvent(EventBus.AUDIO_SPEED, playSpeed)
} }
} }
} }
@ -189,7 +195,11 @@ class AudioPlayService : BaseService(),
*/ */
override fun onPrepared(mp: MediaPlayer?) { override fun onPrepared(mp: MediaPlayer?) {
if (pause) return if (pause) return
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mediaPlayer.playbackParams = mediaPlayer.playbackParams.apply { speed = playSpeed }
} else {
mediaPlayer.start() mediaPlayer.start()
}
mediaPlayer.seekTo(position) mediaPlayer.seekTo(position)
postEvent(EventBus.AUDIO_SIZE, mediaPlayer.duration) postEvent(EventBus.AUDIO_SIZE, mediaPlayer.duration)
bookChapter?.let { bookChapter?.let {

Loading…
Cancel
Save