playback: remove media button reciever impl
Make MediaButtonReceiver an empty class without any behavior. The previous manner in which Auxio would handle media button events was actually bad, as in certain cases (like a rewind or if there was no song playing) Auxio would actually crash, as the service would not start a foreground state in time. Fix this by removing that functionality. This should hopefully still retain the current state.
This commit is contained in:
parent
4a79de455a
commit
5381e9f9a2
4 changed files with 12 additions and 28 deletions
|
@ -18,11 +18,8 @@
|
||||||
package org.oxycblt.auxio.playback.system
|
package org.oxycblt.auxio.playback.system
|
||||||
|
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import org.oxycblt.auxio.util.logD
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some apps like to party like it's 2011 and just blindly query for the ACTION_MEDIA_BUTTON intent
|
* Some apps like to party like it's 2011 and just blindly query for the ACTION_MEDIA_BUTTON intent
|
||||||
|
@ -30,17 +27,10 @@ import org.oxycblt.auxio.util.logD
|
||||||
* MediaSession that an app should control instead through the much better MediaController API. But
|
* MediaSession that an app should control instead through the much better MediaController API. But
|
||||||
* who cares about that, we need to make sure the 3% of barely functioning TouchWiz devices running
|
* who cares about that, we need to make sure the 3% of barely functioning TouchWiz devices running
|
||||||
* KitKat don't break! To prevent Auxio from not showing up at all in these apps, we declare a
|
* KitKat don't break! To prevent Auxio from not showing up at all in these apps, we declare a
|
||||||
* BroadcastReceiver that deliberately handles this event. This also means that Auxio will start
|
* BroadcastReceiver in the manifest that actually does nothing. Any broadcast by apps should be
|
||||||
* without warning if you use the media buttons while the app exists, because I guess we just have
|
* routed by the media session when the service exists.
|
||||||
* to deal with this.
|
|
||||||
* @author OxygenCobalt
|
* @author OxygenCobalt
|
||||||
*/
|
*/
|
||||||
class MediaButtonReceiver : BroadcastReceiver() {
|
class MediaButtonReceiver : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {}
|
||||||
if (intent.action == Intent.ACTION_MEDIA_BUTTON) {
|
|
||||||
logD("Received external media button intent")
|
|
||||||
intent.component = ComponentName(context, PlaybackService::class.java)
|
|
||||||
ContextCompat.startForegroundService(context, intent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,17 +221,16 @@ class MediaSessionComponent(private val context: Context, private val player: Pl
|
||||||
private fun invalidateSessionState() {
|
private fun invalidateSessionState() {
|
||||||
logD("Updating media session playback state")
|
logD("Updating media session playback state")
|
||||||
|
|
||||||
// Position updates arrive faster when you upload STATE_PAUSED, as it resets the clock
|
// Position updates arrive faster when you upload a state that is different, as it
|
||||||
// that updates the position.
|
// forces the system to re-poll the position.
|
||||||
|
// FIXME: For some reason however, positions just DON'T UPDATE AT ALL when you
|
||||||
|
// change from FROM THE APP ONLY WHEN THE PLAYER IS PAUSED. AAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
val state =
|
val state =
|
||||||
PlaybackStateCompat.Builder()
|
PlaybackStateCompat.Builder()
|
||||||
.setActions(ACTIONS)
|
.setActions(ACTIONS)
|
||||||
.setBufferedPosition(player.bufferedPosition)
|
.setBufferedPosition(player.bufferedPosition)
|
||||||
.setState(
|
|
||||||
PlaybackStateCompat.STATE_PAUSED,
|
state.setState(PlaybackStateCompat.STATE_NONE, player.bufferedPosition, 1.0f)
|
||||||
player.currentPosition,
|
|
||||||
1.0f,
|
|
||||||
SystemClock.elapsedRealtime())
|
|
||||||
|
|
||||||
mediaSession.setPlaybackState(state.build())
|
mediaSession.setPlaybackState(state.build())
|
||||||
|
|
||||||
|
|
|
@ -154,12 +154,6 @@ class PlaybackService :
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
||||||
if (intent.action == Intent.ACTION_MEDIA_BUTTON) {
|
|
||||||
// Workaround to get GadgetBridge and other apps that blindly query for
|
|
||||||
// ACTION_MEDIA_BUTTON working.
|
|
||||||
mediaSessionComponent.handleMediaButtonIntent(intent)
|
|
||||||
}
|
|
||||||
|
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +279,6 @@ class PlaybackService :
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onShuffledChanged(isShuffled: Boolean) {
|
override fun onShuffledChanged(isShuffled: Boolean) {
|
||||||
logD("${settingsManager.useAltNotifAction}")
|
|
||||||
if (settingsManager.useAltNotifAction) {
|
if (settingsManager.useAltNotifAction) {
|
||||||
notificationComponent.updateShuffled(isShuffled)
|
notificationComponent.updateShuffled(isShuffled)
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.oxycblt.auxio.util.getDimenSizeSafe
|
||||||
* widget state based off of that. This cannot be rolled into [WidgetProvider] directly, as it may
|
* widget state based off of that. This cannot be rolled into [WidgetProvider] directly, as it may
|
||||||
* result in memory leaks if [PlaybackStateManager]/[SettingsManager] gets created and bound to
|
* result in memory leaks if [PlaybackStateManager]/[SettingsManager] gets created and bound to
|
||||||
* without being released.
|
* without being released.
|
||||||
|
* @author OxygenCobalt
|
||||||
*/
|
*/
|
||||||
class WidgetComponent(private val context: Context) :
|
class WidgetComponent(private val context: Context) :
|
||||||
PlaybackStateManager.Callback, SettingsManager.Callback {
|
PlaybackStateManager.Callback, SettingsManager.Callback {
|
||||||
|
@ -55,7 +56,7 @@ class WidgetComponent(private val context: Context) :
|
||||||
* Force-update the widget.
|
* Force-update the widget.
|
||||||
*/
|
*/
|
||||||
fun update() {
|
fun update() {
|
||||||
// Updating Auxio's widget is unlike the rest of Auxio for two reasons:
|
// Updating Auxio's widget is unlike the rest of Auxio for a few reasons:
|
||||||
// 1. We can't use the typical primitives like ViewModels
|
// 1. We can't use the typical primitives like ViewModels
|
||||||
// 2. The component range is far smaller, so we have to do some odd hacks to get
|
// 2. The component range is far smaller, so we have to do some odd hacks to get
|
||||||
// the same UX.
|
// the same UX.
|
||||||
|
@ -67,6 +68,7 @@ class WidgetComponent(private val context: Context) :
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: Store these values here so they remain consistent once the bitmap is loaded.
|
||||||
val isPlaying = playbackManager.isPlaying
|
val isPlaying = playbackManager.isPlaying
|
||||||
val repeatMode = playbackManager.repeatMode
|
val repeatMode = playbackManager.repeatMode
|
||||||
val isShuffled = playbackManager.isShuffled
|
val isShuffled = playbackManager.isShuffled
|
||||||
|
|
Loading…
Reference in a new issue