Open lguipeng opened 1 year ago
If the media playlist of the HLS stream has the #EXT-X-PROGRAM-DATE-TIME
set, then you can inspect the playlist to get the start time of the playlist and calculate the start time of each segement:
@Override
public void onTimelineChanged(Timeline timeline, int reason) {
int windowIndexOfHlsLiveStream = 0;
Object manifest =
timeline.getWindow(windowIndexOfHlsLiveStream, new Timeline.Window()).manifest;
if (manifest instanceof HlsManifest) {
HlsMediaPlaylist mediaPlaylist = ((HlsManifest) manifest).mediaPlaylist;
long segmentStartUs = mediaPlaylist.startTimeUs;
long mediaSequence = mediaPlaylist.mediaSequence;
Log.d("timeline", "playlist startTimeUs: " + segmentStartUs);
for (int i = 0; i < mediaPlaylist.segments.size(); i++) {
HlsMediaPlaylist.Segment segment = mediaPlaylist.segments.get(i);
Log.d("timeline", "segment with sequence " + (mediaSequence++) + " starts at: " + segmentStartUs);
segmentStartUs += segment.durationUs;
}
}
}
I don't think there is an API to get the currently playing TS
segment though.
As described in the title