如何通过ExoPlayer标签播放媒体?

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

How to play a media through the tag with exoplayer?

问题

一旦我将歌曲添加到concatenatingMediaSource中,我就会在其旁边添加一个标签,因此我想知道如何通过这个特定的标签播放歌曲。

ExtractorMediaSource mediaSource2 = new ExtractorMediaSource.Factory(dataSourceFactory)
       .setTag(ctd)
       .createMediaSource(ssUriTeste);

concatenatingMediaSource.addMediaSource(mediaSource2);

注意:ctd是指向歌曲位置的引用编号;

英文:

As soon as I add a song to the concatenatingMediaSource I add a tag next to it, so I would like to know how to play a song through this specific tag.

 ExtractorMediaSource mediaSource2 = new ExtractorMediaSource.Factory(dataSourceFactory)
       .setTag(ctd)
       .createMediaSource(ssUriTeste);

       concatenatingMediaSource.addMediaSource(mediaSource2);

Obs: ctd is a reference number to the position of the song;

答案1

得分: 1

我无法找到一个返回整个播放列表的函数。

在检查API中的函数时,最适合在播放列表中频繁跳转的应用程序的选项似乎是在播放器外部拥有一个副本,并且只加载当前项目。

然而,如果您需要使用唯一ID从播放列表中访问特定项目,则可能会起作用。

  • 像您提供的代码一样注册您的播放列表,您可以使用.setTag().setMediaId()来唯一标识您的曲目。

  • 使用.getMediaItemAt()获取播放列表项目。

int count = player.getMediaItemCount();

for (int i = 0; i < count; i++) {
    MediaItem media = player.getMediaItemAt(i);
    if(media.mediaId == myDesiredId) {
        // 对媒体执行操作
            
        // 您还可以使用索引i作为起点
        // 删除所有之前的项目,或者使用moveMediaItem将第i个项目移到
        // 播放列表的第一个位置
            
        break;
    }
}

注意:您应该评估循环中多次调用getMediaItemAt()是否会引起问题。

英文:

I haven't been able to find a function that returns the whole playlist.

Examining the functions in the API it looks like the best option for an application that jumps around a lot in the playlist is to have a copy of it outside the player and only load the current item.

However, if you need to access a specific item from the playlist using an unique ID, this will probably work.

  • Register your playlist like the code you provided, you can use .setTag() or .setMediaId() to uniquely identify your tracks

  • Get the playlist items with .getMediaItemAt()

    int count = player.getMediaItemCount();

    for (int i = 0; i &lt; count; i++) {
        MediaItem media = player.getMediaItemAt(i)
        if(media.mediaId == myDesiredId) {
            // do whatever you want with media
            
            // you can also use the index i as a starting point
            // to delete all previous items or to move the i-th item to 
            // the first position of the playlist with moveMediaItem
            
            break;
        }
    }

Note: You should evaluate if the loop with multipla calls to getMediaItemAt() cause a problem.

huangapple
  • 本文由 发表于 2020年9月16日 04:49:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63909676.html
匿名

发表评论

匿名网友

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

确定