如何解决如何使用exoplayer通过标签播放媒体?
在将歌曲添加到concatenatingMediaSource之后,我立即在其旁边添加了一个标签,因此我想知道如何通过此特定标签播放歌曲。
ExtractorMediaSource mediaSource2 = new ExtractorMediaSource.Factory(dataSourceFactory)
.setTag(ctd)
.createMediaSource(ssUriTeste);
concatenatingMediaSource.addMediaSource(mediaSource2);
Obs:ctd是歌曲位置的参考编号;
解决方法
我找不到返回整个播放列表的函数。
检查 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) {
// 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;
}
}
注意:您应该评估对 getMediaItemAt() 进行多次调用的循环是否会导致问题。