Dhams
Dhams

Reputation: 51

How can we achieve seekable progress bar in Android Q OS programatically?

Android Q Beta 2 adds a seekable progress bar for music notifications, so how can we achieve using programming in android Q OS with spotify and soundcloud?

Upvotes: 4

Views: 1070

Answers (1)

Mateusz Kaflowski
Mateusz Kaflowski

Reputation: 2367

You need to add metadata to media session like duration and playback state:

    MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
    builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, currentEpisode.getPodcast().getArtistName());
    builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, currentEpisode.getPodcast().getCollectionName());
    builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, currentEpisode.getTitle());
    builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, currentEpisode.getImageUrl());
    builder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, currentEpisode.id);
    builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, player.getDuration());
    mediaSessionCompat.setMetadata(builder.build());

    PlaybackStateCompat playbackStateCompat = new PlaybackStateCompat.Builder()
            .setActions(
                    PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE |
                            PlaybackStateCompat.ACTION_FAST_FORWARD | PlaybackStateCompat.ACTION_REWIND |
                            PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID | PlaybackStateCompat.ACTION_PAUSE |
                            PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS | PlaybackStateCompat.ACTION_SEEK_TO)
            .setState(state, position, speedRate)
            .build();

    mediaSessionCompat.setPlaybackState(playbackStateCompat);

PlaybackStateCompat.ACTION_SEEK_TO gives you seeking ability additionally.

Upvotes: 5

Related Questions