如何在ExoPlayer中为每个当前的MediaItem从API预加载和更新?

huangapple go评论72阅读模式
英文:

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

问题

我有一个Android项目,它提供了一个音乐播放列表的API,但不包括URL(只有ID、标题和图片),还有另一个API,根据ID提供音乐的详细信息,包括URL和其他信息。我正在使用ExoPlayer2。

这是我的问题,我想首先在ExoPlayer中准备一个没有URL的播放列表。在播放该播放列表时,我想从我的音乐详细信息API中加载当前音乐的URL,并更新到ExoPlayer中的当前播放列表。

你能否给我提供最佳解决方案建议?

目前,我正在用一个笨拙的方法来解决。当我从API获取播放列表时,我循环遍历每首音乐,首先调用每首音乐的详细信息。然后,我将它们转化为“MediaSource”并设置到ExoPlayer中。
这样做是可行的,但如你所猜测的,播放一个播放列表需要很长时间。

英文:

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

得分: 1

首先,如果你只有一个 ID,而无法创建 MediaSource,你可以将 MediaItem 传递给播放器实例。

MediaSource 将通过 MediaSource.Factory 创建,你可以使用 DefaultMediaSourceFactory 或其他适合你的用例的工厂。

之后,你可以查看这个 GitHub 上的问题,其中来自 ExoPlayer 团队的 marcbaechinger 回答了一个类似的问题。
https://github.com/google/ExoPlayer/issues/10200

英文:

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

huangapple
  • 本文由 发表于 2023年2月24日 01:04:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75548056.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定