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