pull/32/head
kunfei 5 years ago
parent 9035e15c3e
commit 8c456a8b62
  1. 9
      app/src/main/java/io/legado/app/help/MediaHelp.kt
  2. 9
      app/src/main/java/io/legado/app/service/ReadAloudService.kt

@ -2,10 +2,17 @@ package io.legado.app.help
import android.content.Context import android.content.Context
import android.media.MediaPlayer import android.media.MediaPlayer
import android.support.v4.media.session.PlaybackStateCompat
import io.legado.app.R import io.legado.app.R
object MediaHelp { object MediaHelp {
const val MEDIA_SESSION_ACTIONS = (PlaybackStateCompat.ACTION_PLAY
or PlaybackStateCompat.ACTION_PAUSE
or PlaybackStateCompat.ACTION_PLAY_PAUSE
or PlaybackStateCompat.ACTION_SKIP_TO_NEXT
or PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
or PlaybackStateCompat.ACTION_STOP
or PlaybackStateCompat.ACTION_SEEK_TO)
fun playSilentSound(mContext: Context) { fun playSilentSound(mContext: Context) {
try { try {

@ -30,13 +30,6 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
companion object { companion object {
val tag: String = ReadAloudService::class.java.simpleName val tag: String = ReadAloudService::class.java.simpleName
var isRun = false var isRun = false
const val MEDIA_SESSION_ACTIONS = (PlaybackStateCompat.ACTION_PLAY
or PlaybackStateCompat.ACTION_PAUSE
or PlaybackStateCompat.ACTION_PLAY_PAUSE
or PlaybackStateCompat.ACTION_SKIP_TO_NEXT
or PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
or PlaybackStateCompat.ACTION_STOP
or PlaybackStateCompat.ACTION_SEEK_TO)
fun paly(context: Context, title: String, body: String) { fun paly(context: Context, title: String, body: String) {
@ -224,7 +217,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
private fun upMediaSessionPlaybackState() { private fun upMediaSessionPlaybackState() {
mediaSessionCompat?.setPlaybackState( mediaSessionCompat?.setPlaybackState(
PlaybackStateCompat.Builder() PlaybackStateCompat.Builder()
.setActions(MEDIA_SESSION_ACTIONS) .setActions(MediaHelp.MEDIA_SESSION_ACTIONS)
.setState( .setState(
if (speak) PlaybackStateCompat.STATE_PLAYING else PlaybackStateCompat.STATE_PAUSED, if (speak) PlaybackStateCompat.STATE_PLAYING else PlaybackStateCompat.STATE_PAUSED,
nowSpeak.toLong(), 1f nowSpeak.toLong(), 1f

Loading…
Cancel
Save