Work around double headset KEYCODE_MEDIA_PAUSE event. Also, update some

dependencies and ensure ambiguous versions are pinned.
This commit is contained in:
casey langen 2019-03-29 22:16:51 -07:00
parent b082031357
commit 4c1821f863
2 changed files with 41 additions and 6 deletions

View File

@ -55,7 +55,7 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation(name:'android-taskrunner-0.5', ext:'aar')
implementation(name:'exoplayer-extension-flac-release-v2', ext:'aar')
@ -75,15 +75,15 @@ dependencies {
kapt 'com.google.dagger:dagger-compiler:2.19'
implementation 'com.neovisionaries:nv-websocket-client:1.31'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation "com.github.bumptech.glide:okhttp3-integration:4.8.0"
kapt 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
implementation 'com.google.android.exoplayer:exoplayer:2.9.4'
implementation 'com.google.android.exoplayer:extension-okhttp:2.9.4'
implementation 'com.google.android.exoplayer:exoplayer:2.9.6'
implementation 'com.google.android.exoplayer:extension-okhttp:2.9.6'
implementation 'com.simplecityapps:recyclerview-fastscroll:1.0.20'
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.github.wooplr:Spotlight:1.2.3'
@ -99,4 +99,11 @@ dependencies {
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
configurations.all {
resolutionStrategy {
force 'com.android.support:animated-vector-drawable:28.0.0'
force 'com.android.support:support-v4:28.0.0'
}
}
}

View File

@ -52,6 +52,13 @@ class SystemService : Service() {
private var mediaSession: MediaSessionCompat? = null
private var headsetHookPressCount = 0
/* if we pause via headset on some devices, and unpause immediately after,
the runtime will erroneously issue a second KEYCODE_MEDIA_PAUSE command,
instead of KEYCODE_MEDIA_RESUME. to work around this, if we pause from a
headset, we flip this bit for a couple seconds, which will be used as a
hint that we should resume if we get another KEYCODE_MEDIA_PAUSE. */
private var headsetDoublePauseHack = false
private lateinit var powerManager: PowerManager
private lateinit var prefs: SharedPreferences
@ -402,7 +409,8 @@ class SystemService : Service() {
return false
}
private val headsetHookDebouncer = object : Debouncer<Void>(HEADSET_HOOK_DEBOUNCE_MS) {
private val headsetHookDebouncer =
object: Debouncer<Void>(HEADSET_HOOK_DEBOUNCE_MS) {
override fun onDebounced(last: Void?) {
playback?.let {
when (headsetHookPressCount) {
@ -415,6 +423,13 @@ class SystemService : Service() {
}
}
private val headsetDoublePauseHackDebouncer =
object: Debouncer<Void>(HEADSET_DOUBLE_PAUSE_HACK_DEBOUNCE_MS) {
override fun onDebounced(last: Void?) {
headsetDoublePauseHack = false
}
}
private val mediaSessionCallback = object : MediaSessionCompat.Callback() {
override fun onMediaButtonEvent(mediaButtonEvent: Intent?): Boolean {
if (Intent.ACTION_MEDIA_BUTTON == mediaButtonEvent?.action) {
@ -447,7 +462,15 @@ class SystemService : Service() {
return true
}
KeyEvent.KEYCODE_MEDIA_PAUSE -> {
playback?.pause()
if (headsetDoublePauseHack) {
playback?.resume()
headsetDoublePauseHack = false
}
else {
playback?.pause()
headsetDoublePauseHack = true
headsetDoublePauseHackDebouncer.call()
}
return true
}
KeyEvent.KEYCODE_MEDIA_PLAY -> {
@ -491,6 +514,10 @@ class SystemService : Service() {
}
private val playbackListener = {
/* freaking sigh... */
if (playback?.state == PlaybackState.Playing) {
headsetDoublePauseHack = false
}
updateMediaSessionPlaybackState()
}
@ -557,6 +584,7 @@ class SystemService : Service() {
private const val NOTIFICATION_ID = 0xdeadbeef.toInt()
private const val NOTIFICATION_CHANNEL = "musikdroid"
private const val HEADSET_HOOK_DEBOUNCE_MS = 500L
private const val HEADSET_DOUBLE_PAUSE_HACK_DEBOUNCE_MS = 3500L
private const val ACTION_NOTIFICATION_PLAY = "io.casey.musikcube.remote.NOTIFICATION_PLAY"
private const val ACTION_NOTIFICATION_PAUSE = "io.casey.musikcube.remote.NOTIFICATION_PAUSE"
private const val ACTION_NOTIFICATION_NEXT = "io.casey.musikcube.remote.NOTIFICATION_NEXT"