Exoplayer: How to attach media meta info while using offline package to cache and retrieve it later in another class

Created on 27 Feb 2020  路  2Comments  路  Source: google/ExoPlayer

Searched documentation and issues and in Demo app, DownloadTracker and PlayerActivity class from the demo

[REQUIRED] Question

How to attach extra meta info like id, artist name, artwork url, title etc while using DownloadManager from offline package to cache media files and retrieve it later with it's status?

I am able to cache the media files but not able to attach extra info with the downloaded item so that I can later query it and display it in another screen where it can be played offline

I checked out DownloadTracker class from the demo app but it does not provide required info on how to get it done.

question

Most helpful comment

I don't think Cache is the right level of API to be using for this.

I think you should be using DownloadRequest.data. When you create a DownloadRequest to download an item, you can serialize whatever custom data you want into that field, and it will be persisted along with information about the download. Whenever you query the downloads, you can retrieve the data from Download.request.data. Serializing and de-serializing the responsibility of the app developer.

All 2 comments

Create a ContentMetadataMutations instance, set custom key/value pairs (using ContentMetadata.KEY_CUSTOM_PREFIX to avoid colliding with ExoPlayer's metadata keys) then apply those mutations via Cache.applyContentMetadataMutations on the cache that you're passing to DownloadManager. Metadata can be retrieved via Cache.getContentMetadata. @ojw28 Please correct this if I've missed something. Thanks.

I don't think Cache is the right level of API to be using for this.

I think you should be using DownloadRequest.data. When you create a DownloadRequest to download an item, you can serialize whatever custom data you want into that field, and it will be persisted along with information about the download. Whenever you query the downloads, you can retrieve the data from Download.request.data. Serializing and de-serializing the responsibility of the app developer.

Was this page helpful?
0 / 5 - 0 ratings