|
|
@ -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 { |
|
|
|