androidx / androidx/media

Unable to put STOP button - Android Auto - Legacy MediaBrowserServiceCompat

Open
#1,775 0 comments 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Oct 7, 2024.

needs triage question
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

Hi I'm trying to put the stop button in the player screen and remove all other buttons:

mMediaSession = MediaSessionCompat(
                this,
                "MediaSessionCompat_TAG"
            ).apply {
                val sessionActivityPendingIntent =
                    packageManager?.getLaunchIntentForPackage(packageName)?.let { sessionIntent ->
                        PendingIntent.getActivity(this@AudioService, 0, sessionIntent, 0)
                    }
                setSessionActivity(sessionActivityPendingIntent)
                isActive = true
                setCallback(mediaSessionCallback)
                setPlaybackState(
                    playbackStateBuilder.apply {
                        setState(PlaybackStateCompat.STATE_STOPPED, C.TIME_UNSET, 1f)
                        setActions(PlaybackStateCompat.ACTION_STOP)
                    }.build()
                )
                setSessionToken(sessionToken)
            ...
            
            In addition I put in the MediaControllerCallback the value of stop
                
                @Suppress("PropertyName")
val EMPTY_PLAYBACK_STATE: PlaybackStateCompat = PlaybackStateCompat.Builder()
    .setState(PlaybackStateCompat.STATE_STOPPED, C.TIME_UNSET, 0f)
    .build()
    
        private inner class MediaControllerCallback : MediaControllerCompat.Callback() {

        override fun onPlaybackStateChanged(state: PlaybackStateCompat?) {
            playbackState.postValue(EMPTY_PLAYBACK_STATE)
        }

        override fun onMetadataChanged(metadata: MediaMetadataCompat?) {
            playbackState.postValue(EMPTY_PLAYBACK_STATE)
            nowPlaying.postValue(
                if (metadata?.id == null) {
                    NOTHING_PLAYING
                } else {
                    metadata
                }
            )
        }

        override fun onQueueChanged(queue: MutableList<MediaSessionCompat.QueueItem>?) {
            playbackState.postValue(EMPTY_PLAYBACK_STATE)
        }

        override fun onSessionEvent(event: String?, extras: Bundle?) {
            playbackState.postValue(EMPTY_PLAYBACK_STATE)
            super.onSessionEvent(event, extras)
            when (event) {
                NETWORK_FAILURE -> networkFailure.postValue(true)
            }
        }

I only get the PLAY button and periodically a blink show and hide the previous and next buttons

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.