|
|
@ -22,14 +22,19 @@ class MediaButtonReceiver : BroadcastReceiver() { |
|
|
|
fun handleIntent(context: Context, intent: Intent): Boolean { |
|
|
|
fun handleIntent(context: Context, intent: Intent): Boolean { |
|
|
|
val intentAction = intent.action |
|
|
|
val intentAction = intent.action |
|
|
|
if (Intent.ACTION_MEDIA_BUTTON == intentAction) { |
|
|
|
if (Intent.ACTION_MEDIA_BUTTON == intentAction) { |
|
|
|
val event = intent.getParcelableExtra<KeyEvent>(Intent.EXTRA_KEY_EVENT) ?: return false |
|
|
|
val event = |
|
|
|
|
|
|
|
intent.getParcelableExtra<KeyEvent>(Intent.EXTRA_KEY_EVENT) ?: return false |
|
|
|
|
|
|
|
|
|
|
|
val keycode = event.keyCode |
|
|
|
val keycode = event.keyCode |
|
|
|
val action = event.action |
|
|
|
val action = event.action |
|
|
|
|
|
|
|
|
|
|
|
var command = false |
|
|
|
var command = false |
|
|
|
when (keycode) { |
|
|
|
when (keycode) { |
|
|
|
KeyEvent.KEYCODE_MEDIA_STOP, KeyEvent.KEYCODE_MEDIA_PAUSE, KeyEvent.KEYCODE_MEDIA_PLAY, KeyEvent.KEYCODE_HEADSETHOOK, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE -> { |
|
|
|
KeyEvent.KEYCODE_MEDIA_STOP, |
|
|
|
|
|
|
|
KeyEvent.KEYCODE_MEDIA_PAUSE, |
|
|
|
|
|
|
|
KeyEvent.KEYCODE_MEDIA_PLAY, |
|
|
|
|
|
|
|
KeyEvent.KEYCODE_HEADSETHOOK, |
|
|
|
|
|
|
|
KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE -> { |
|
|
|
command = true |
|
|
|
command = true |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|