Hi,
Is there any method to update MediaDescriptionCompat after downloading album artwork from asynctask? I need to download artwork on background thread and update locksrceen image after downloading completes.
This involves updating the queue and the metadata of the to the media session.
How you do this depends on how you are publishing the queue and the metadata to the session. The standard way to do this with the MediaSessionConnector is using the TimelineQueueNavigator (which publishes the queue to the session) and the MediaSessionConnector.DefaultMetadataProvider (which provides the metadata derived from the queue).
Given you are using these two you need to do the following:
1) Receive the bitmap in your AsyncTask and update your backing data of the media items.
2) Now call mediaSessionConnector.invalidateMediaSessionQueue() which makes the TimelineQueueNavigator update the queue in session. You had implemented the abstract method TimelineQueueNavigator.getMediaDescription(player, window) which is now called for each item in the queue. Provide the downloaded image.
3) Finally you need to call mediaSessionConnector.invalidateMediaSessionMetadata() which makes the DefaultMetadataProvider take the data of the MediaDescriptionCompat of the current active item and publishes it as the current metadata by calling mediaSession.setMetadata().
@marcbaechinger Thanks a lot. It would be nice if it was mentioned clearly in document.
I looked at the Java docs of the methods (see below) which mention that these need to be called when the data changes and needs to be updated on demand. The javadoc of the DefaultMediaMetadataProvider says that the metadata is taken from the active queue item.
But I acknowledge that this is not obvious, because the behaviour is created as a result of the interaction of various components.
I'm happy to make this more clear in the docs somehow. May I ask some questions?
Let me know your thoughts please.
/**
* Updates the metadata of the media session.
*
* <p>Apps normally only need to call this method when the backing data for a given media item has
* changed and the metadata should be updated immediately.
*/
public final void invalidateMediaSessionPlaybackState() {)
/**
* Updates the queue of the media session by calling {@link
* QueueNavigator#onTimelineChanged(Player)}.
*
* <p>Apps normally only need to call this method when the backing data for a given queue item has
* changed and the queue should be updated immediately.
*/
public final void invalidateMediaSessionQueue() {}
/**
* Provides a default {@link MediaMetadataCompat} with properties and extras propagated from the
* active queue item to the session metadata.
*/
public static final class DefaultMediaMetadataProvider implements MediaMetadataProvider {
Yes, I was able to find the java doc in Android Studio. I was looking the doc from web which is more convenient. I am new to ExoPlayer so I followed the developer guide here . It is not only about lock screen image it is also about large icon on notification. I needed to download artwork asynchronously and update lockscreen image as well as notification large icon.
Many thanks for your input. We updated the javadoc for a couple of classes to have you case documented more prominently (see commit message above). I'm closing for now. Please reopen and let us nkow wheteher I can help you some further.
Most helpful comment
This involves updating the queue and the metadata of the to the media session.
How you do this depends on how you are publishing the queue and the metadata to the session. The standard way to do this with the
MediaSessionConnectoris using theTimelineQueueNavigator(which publishes the queue to the session) and theMediaSessionConnector.DefaultMetadataProvider(which provides the metadata derived from the queue).Given you are using these two you need to do the following:
1) Receive the bitmap in your
AsyncTaskand update your backing data of the media items.2) Now call
mediaSessionConnector.invalidateMediaSessionQueue()which makes theTimelineQueueNavigatorupdate the queue in session. You had implemented the abstract methodTimelineQueueNavigator.getMediaDescription(player, window)which is now called for each item in the queue. Provide the downloaded image.3) Finally you need to call
mediaSessionConnector.invalidateMediaSessionMetadata()which makes theDefaultMetadataProvidertake the data of theMediaDescriptionCompatof the current active item and publishes it as the current metadata by callingmediaSession.setMetadata().