How can i pre-load and update for each current MediaItem from an API in ExoPlayer?

455 Views Asked by At

I have an android project that gives me an API of a music playlist without urls (just ids, titles and images) and has another API that will give me music detail by id including url and other information. I'm using ExoPlayer2.

Here is my problem, I want to prepare a playlist without urls first in ExoPlayer. When playing that playlist, I want to load the current music's url from my music detail API and update to that current playing list in ExoPlayer.

Can you please suggest me for the best solutions?

Currently, I'm solving in stupid way. That's when I want got a playlist from API, I looped and call details for each music first. After that, I transformed them as MediaSource and set to ExoPlayer. It's worked. But as you guest, it takes a lot of time to play a playlist.

1

There are 1 best solutions below

0
Stronger197 On

First of all, if you only have an id and you can't create a MediaSource, you can pass the MediaItem to the player instance.

MediaSource will be created via MediaSource.Factory you can use DefaultMediaSourceFactory or others, depending on your use case

After that, you can check out this issue on github, where marcbaechinger from exoplayer team answered a similar question. https://github.com/google/ExoPlayer/issues/10200