Does ExoPlayer Expose a Way to Tell Sliding vs. Complete Live Playlists

时间:2018-03-23 00:12:16

标签: android exoplayer exoplayer2.x

I am using ExoPlayer 2.6.1 to play live HLS, and have the need to be able to tell if the HLS playlist is a sliding window or a complete playlist (that is ever growing). I want to display different player controls based on which type of playlist is being used, and I do not have access to that metadata. So I was curious if it was possible to get that information from the ExoPlayer itself.

I thought that I could be able to use the Timeline as described here, but I cannot seem to be able to tell the difference.

1 个答案:

答案 0 :(得分:0)

HLS播放列表可以有三种不同的类型:live(默认),event或vod(spec)。对于event或vod,可以使用

在播放列表中设置类型
#EXT-X-PLAYLIST-TYPE:EVENT

#EXT-X-PLAYLIST-TYPE:VOD

根据spec,EVENT类型就是您所谓的完整实时播放列表:

  

清单2中显示的事件播放列表具有与live相同的格式   上面的媒体播放列表,但额外的一行除外:    #EXT-X-PLAYLIST-TYPE:事件。该指定提醒媒体播放器该播放列表的行为将与实况媒体播放列表不同。   事件播放列表在获得时保持对旧媒体的引用   新的参考文献。

使用ExoPlayer,您可以注册一个监听器来监听时间轴更改。回调有一个清单参数,你可以参考:

player.addListener(new Player.DefaultEventListener() {
  @Override
  public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {
    if (manifest != null) {
      switch (((HlsManifest)manifest).mediaPlaylist.playlistType) {
        case HlsMediaPlaylist.PLAYLIST_TYPE_VOD:
          Log.d("TAG", "playlist type VOD");
          break;
        case HlsMediaPlaylist.PLAYLIST_TYPE_EVENT:
          Log.d("TAG", "playlist type EVENT");
          break;
        default:
          Log.d("TAG", "playlist type LIVE");
          break;
      }
    }
  }
});