pull/34/head
kunfei 5 years ago
parent f095d87f61
commit ff4347e676
  1. 21
      app/src/main/java/io/legado/app/help/MediaHelp.kt
  2. 9
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt

@ -11,16 +11,27 @@ import androidx.annotation.RequiresApi
import io.legado.app.R
object MediaHelp {
const val MEDIA_SESSION_ACTIONS = (PlaybackStateCompat.ACTION_PLAY
or PlaybackStateCompat.ACTION_PAUSE
const val MEDIA_SESSION_ACTIONS = (PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
or PlaybackStateCompat.ACTION_REWIND
or PlaybackStateCompat.ACTION_PLAY
or PlaybackStateCompat.ACTION_PLAY_PAUSE
or PlaybackStateCompat.ACTION_SKIP_TO_NEXT
or PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
or PlaybackStateCompat.ACTION_PAUSE
or PlaybackStateCompat.ACTION_STOP
or PlaybackStateCompat.ACTION_FAST_FORWARD
or PlaybackStateCompat.ACTION_SKIP_TO_NEXT
or PlaybackStateCompat.ACTION_SEEK_TO
or PlaybackStateCompat.ACTION_SET_RATING
or PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID
or PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH
or PlaybackStateCompat.ACTION_PLAY_FROM_URI)
or PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM
or PlaybackStateCompat.ACTION_PLAY_FROM_URI
or PlaybackStateCompat.ACTION_PREPARE
or PlaybackStateCompat.ACTION_PREPARE_FROM_MEDIA_ID
or PlaybackStateCompat.ACTION_PREPARE_FROM_SEARCH
or PlaybackStateCompat.ACTION_PREPARE_FROM_URI
or PlaybackStateCompat.ACTION_SET_REPEAT_MODE
or PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE
or PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED)
@RequiresApi(Build.VERSION_CODES.O)
fun getFocusRequest(audioFocusChangeListener: AudioManager.OnAudioFocusChangeListener): AudioFocusRequest {

@ -25,22 +25,13 @@ class MediaButtonReceiver : BroadcastReceiver() {
val event =
intent.getParcelableExtra<KeyEvent>(Intent.EXTRA_KEY_EVENT) ?: return false
val keycode = event.keyCode
val action = event.action
when (keycode) {
KeyEvent.KEYCODE_MEDIA_STOP,
KeyEvent.KEYCODE_MEDIA_PAUSE,
KeyEvent.KEYCODE_MEDIA_PLAY,
KeyEvent.KEYCODE_HEADSETHOOK,
KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE -> {
if (action == KeyEvent.ACTION_DOWN) {
readAloud(context)
return true
}
}
}
}
return false
}

Loading…
Cancel
Save