ExoPlayer 2.18.5 getSelectedTrack 函数被移除:替代方法及TrackGroup选中判断
在 ExoPlayer 2.18.5 中,getSelectedTrack 函数已被删除。取而代之的是使用 getSelectedFormat 函数来获取当前选中的 Track 的 Format。这个函数返回当前选中的 Track 的 Format,如果没有选中的 Track,则返回 null。
要判断一个 TrackGroup 是否被选中,可以使用以下代码:
TrackGroupArray trackGroups = trackSelector.getCurrentMappedTrackInfo().getTrackGroups(rendererIndex);
TrackGroup trackGroup = trackGroups.get(groupIndex);
int selectedIndex = trackSelector.getCurrentMappedTrackInfo().getSelectedTrackIndex(rendererIndex, groupIndex);
boolean isSelected = (selectedIndex != C.INDEX_UNSET && trackGroup.length > 0 && trackGroup.getFormat(selectedIndex) != null);
其中,rendererIndex 是渲染器的索引,groupIndex 是 TrackGroup 的索引。isSelected 变量将会是 true,如果选中了该 TrackGroup,否则为 false。
原文地址: https://www.cveoy.top/t/topic/jNII 著作权归作者所有。请勿转载和采集!