pull/49/head
kunfei 5 years ago
parent 4e512598bf
commit f49247998a
  1. 1
      app/src/main/java/io/legado/app/constant/Action.kt
  2. 8
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  3. 8
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  4. 15
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  5. 2
      app/src/main/res/layout/activity_audio_play.xml

@ -12,6 +12,7 @@ object Action {
const val nextParagraph = "nextParagraph"
const val upTtsSpeechRate = "upTtsSpeechRate"
const val adjustProgress = "adjustProgress"
const val adjustSpeed = "adjustSpeed"
const val prev = "prev"
const val next = "next"
const val moveTo = "moveTo"

@ -88,6 +88,7 @@ class AudioPlayService : BaseService(),
Action.resume -> resume()
Action.prev -> moveToPrev()
Action.next -> moveToNext()
Action.adjustSpeed -> upSpeed()
Action.moveTo -> moveTo(intent.getIntExtra("index", AudioPlay.durChapterIndex))
Action.addTimer -> addTimer()
Action.setTimer -> setTimer(intent.getIntExtra("minute", 0))
@ -160,12 +161,12 @@ class AudioPlayService : BaseService(),
}
}
private fun changeplayerSpeed(speed: Float) {
private fun upSpeed() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (mediaPlayer.isPlaying) {
mediaPlayer.playbackParams = mediaPlayer.playbackParams.setSpeed(speed)
mediaPlayer.playbackParams = mediaPlayer.playbackParams.setSpeed(AudioPlay.speed)
} else {
mediaPlayer.playbackParams = mediaPlayer.playbackParams.setSpeed(speed)
mediaPlayer.playbackParams = mediaPlayer.playbackParams.setSpeed(AudioPlay.speed)
mediaPlayer.pause()
}
}
@ -179,6 +180,7 @@ class AudioPlayService : BaseService(),
mp?.let {
mp.start()
mp.seekTo(position)
upSpeed()
postEvent(Bus.AUDIO_SIZE, mp.duration)
bookChapter?.let {
it.end = mp.duration.toLong()

@ -52,6 +52,14 @@ object AudioPlay {
}
}
fun adjustSpeed(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.adjustSpeed
context.startService(intent)
}
}
fun adjustProgress(context: Context, position: Int) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)

@ -46,6 +46,7 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
}
private fun initView() {
tv_speed.text = AudioPlay.speed.toString()
fab_play_stop.onClick {
playButton()
}
@ -86,10 +87,20 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
iv_fast_forward.invisible()
}
iv_fast_forward.onClick {
AudioPlay.speed = AudioPlay.speed + 0.1f
tv_speed.text = AudioPlay.speed.toString()
if (AudioPlay.speed == 1f) {
tv_speed.invisible()
} else {
tv_speed.visible()
}
AudioPlay.adjustSpeed(this)
}
iv_fast_rewind.onClick {
if (AudioPlay.speed > 0.5f) {
AudioPlay.speed = AudioPlay.speed - 0.1f
}
AudioPlay.adjustSpeed(this)
}
}

@ -29,7 +29,7 @@
app:layout_constraintTop_toBottomOf="@+id/title_bar"
app:layout_constraintBottom_toBottomOf="parent" />
<io.legado.app.ui.widget.BadgeView
<TextView
android:id="@+id/tv_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

Loading…
Cancel
Save