Skip to content

How to update current media metadata (user rating) without interrupting the playback? #33

Description

@yareg-com

I am using androidx.media3 to develop an audio player app which provides users with an option to rate currently playng media. So, inside my MediaSessionCallback I do this:

override fun onSetRating(
    session: MediaSession,
    controller: ControllerInfo,
    rating: Rating
): ListenableFuture<SessionResult> {

    val item = session.player.currentMediaItem

    item?.let {
        val metadata  = it.mediaMetadata.buildUpon().setUserRating(rating).build()
        val mediaItem = it.buildUpon().setMediaMetadata(metadata).build()
        session.player.setMediaItem(mediaItem, false)
    }
    
    return Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
}

This works, but with the only caveat - it interrupts the audio for the moment. Please, help me to understand how user rating should work.

Metadata

Metadata

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions