playback: do not check for version w/notification

Do not check for the version when managing the notification.

Some OEMs will update the android system, causing the version number to
change, but will THEN not update the system UI, completely breaking my
compat hacks. Because you know. Reasons. Fix this by always applying
future and obsolete methods of updating the media notification
regardless of the context.

Resolves #219.
This commit is contained in:
Alexander Capehart 2022-08-27 14:09:20 -06:00
parent 4d8c2abd09
commit 5b2817b2f2
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 33 additions and 49 deletions

View file

@ -14,8 +14,9 @@
- Added a way to access the system equalizer from the playback menu. - Added a way to access the system equalizer from the playback menu.
#### What's Fixed #### What's Fixed
- Fixed "@android:string/<ok/cancel>" strings from appearing in dialog - Fixed "@android:string/<ok/cancel>" strings from appearing in dialog
buttons buttons
- Fixed issue where LG phones would not show metadata in the notification
#### What's Changed #### What's Changed
- Menus are now opened using a new button to the side of all items - Menus are now opened using a new button to the side of all items

View file

@ -21,7 +21,6 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.Bitmap import android.graphics.Bitmap
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.SystemClock import android.os.SystemClock
import android.support.v4.media.MediaDescriptionCompat import android.support.v4.media.MediaDescriptionCompat
@ -62,9 +61,6 @@ import org.oxycblt.auxio.util.logD
* @author OxygenCobalt * @author OxygenCobalt
* *
* TODO: Remove the player callback once smooth seeking is implemented * TODO: Remove the player callback once smooth seeking is implemented
*
* TODO: Rework what is considered to "start foreground" and what is not from the context of this
* object. This could help reduce the amount of post calls I send on Android 13 onwards, hopefully.
*/ */
class MediaSessionComponent( class MediaSessionComponent(
private val context: Context, private val context: Context,
@ -229,11 +225,7 @@ class MediaSessionComponent(
override fun onPlayingChanged(isPlaying: Boolean) { override fun onPlayingChanged(isPlaying: Boolean) {
invalidateSessionState() invalidateSessionState()
notification.updatePlaying(playbackManager.isPlaying)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
// Android 13 automatically handles the playing state.
notification.updatePlaying(playbackManager.isPlaying)
}
if (!provider.isBusy) { if (!provider.isBusy) {
// Still probably want to start the notification though regardless of the version, // Still probably want to start the notification though regardless of the version,
@ -409,49 +401,45 @@ class MediaSessionComponent(
state.setState(playerState, player.currentPosition, 1.0f, SystemClock.elapsedRealtime()) state.setState(playerState, player.currentPosition, 1.0f, SystemClock.elapsedRealtime())
// Android 13+ leverages custom actions. // Android 13+ leverages custom actions in the notification.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { val extraAction =
val extraAction = if (settings.useAltNotifAction) {
if (settings.useAltNotifAction) {
PlaybackStateCompat.CustomAction.Builder(
PlaybackService.ACTION_INVERT_SHUFFLE,
context.getString(R.string.desc_change_repeat),
if (playbackManager.isShuffled) {
R.drawable.ic_shuffle_on_24
} else {
R.drawable.ic_shuffle_off_24
})
} else {
PlaybackStateCompat.CustomAction.Builder(
PlaybackService.ACTION_INC_REPEAT_MODE,
context.getString(R.string.desc_change_repeat),
playbackManager.repeatMode.icon)
}
val exitAction =
PlaybackStateCompat.CustomAction.Builder( PlaybackStateCompat.CustomAction.Builder(
PlaybackService.ACTION_EXIT, PlaybackService.ACTION_INVERT_SHUFFLE,
context.getString(R.string.desc_exit), context.getString(R.string.desc_change_repeat),
R.drawable.ic_close_24) if (playbackManager.isShuffled) {
.build() R.drawable.ic_shuffle_on_24
} else {
R.drawable.ic_shuffle_off_24
})
} else {
PlaybackStateCompat.CustomAction.Builder(
PlaybackService.ACTION_INC_REPEAT_MODE,
context.getString(R.string.desc_change_repeat),
playbackManager.repeatMode.icon)
}
state.addCustomAction(extraAction.build()) val exitAction =
state.addCustomAction(exitAction) PlaybackStateCompat.CustomAction.Builder(
} PlaybackService.ACTION_EXIT,
context.getString(R.string.desc_exit),
R.drawable.ic_close_24)
.build()
state.addCustomAction(extraAction.build())
state.addCustomAction(exitAction)
mediaSession.setPlaybackState(state.build()) mediaSession.setPlaybackState(state.build())
} }
private fun invalidateSecondaryAction() { private fun invalidateSecondaryAction() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { invalidateSessionState()
invalidateSessionState()
if (settings.useAltNotifAction) {
notification.updateShuffled(playbackManager.isShuffled)
} else { } else {
if (settings.useAltNotifAction) { notification.updateRepeatMode(playbackManager.repeatMode)
notification.updateShuffled(playbackManager.isShuffled)
} else {
notification.updateRepeatMode(playbackManager.repeatMode)
}
} }
if (!provider.isBusy) { if (!provider.isBusy) {

View file

@ -67,11 +67,6 @@ class NotificationComponent(private val context: Context, sessionToken: MediaSes
// --- STATE FUNCTIONS --- // --- STATE FUNCTIONS ---
fun updateMetadata(metadata: MediaMetadataCompat) { fun updateMetadata(metadata: MediaMetadataCompat) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Notification is automatically filled in by media session, ignore
return
}
setContentTitle(metadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE)) setContentTitle(metadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE))
setContentText(metadata.getText(MediaMetadataCompat.METADATA_KEY_ARTIST)) setContentText(metadata.getText(MediaMetadataCompat.METADATA_KEY_ARTIST))