You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working with a live HLS stream and need to obtain information about the last segment that has been added to the playlist (m3u8) without directly reading the manifest from ExoPlayer.
Context
Here is an example of an HLS manifest (m3u8) I am working with:
I need to detect when a new segment has been loaded into the playlist and get information about it, but without directly analyzing the manifest from the code. In other words, I want to know when ExoPlayer detects and loads a new segment during real-time playback.
Specific Questions:
Does ExoPlayer have any method or listener that allows you to identify when a new segment is loaded in a live HLS stream?
If no specific method exists, what would be the best way to achieve this behavior with ExoPlayer?
Any guidance or examples would be greatly appreciated. Thanks in advance!
The text was updated successfully, but these errors were encountered:
without directly reading the manifest from ExoPlayer.
I understand with this you mean reading the text HLS playlist. Because the information you are asking for is actually in the playlist and you have to read the HLS playlist for that (aka. manifest). However, ExoPlayer parses it for you and provides you with an object that contains the information ExoPlayer extracts from the playlist. The segments are part of that.
If that's ok, the you can add a Player.Listener and listen for onTimelineChanged(Timeline, ...) events.
You can then get the Timeline.Window of the stream you are interested in. For HLS, there is a field window.manifest that gives you an object that for HLS can be casted to a HlsManifest from where you can get the mediaPlaylist field which is of type HlsMediaPlaylist. This object contains all the information ExoPlayer parses from the media playlist which includes the segments:
The interval for refreshing depends on the stream. You can use mediaPlaylist.mediaSequence to see whether the playlist has dropped a segment at the beginning of the live window. Each time a segment is removed from the start of the live window, that sequence is incremented. So together with the mediaSequence and the size of the list of segements, you can figure out whether a new segment has been added. There may be other ways for this as well, just saying. :)
Please note that the mediaPlaylist.manifest fields is null until you receive the first timeline change with TIMELINE_CHANGE_REASON_SOURCE_REFRESH for the window of interest.
Please also note that the above snippet uses windowIndexOfInterest to express that this may vary depending on what's in the global timeline and when you execute this code. For a player that always plays a single item only (which is likely if you are playing a live HLS stream) you can use 0 or the current media item index to make that simple. The example above uses the currentMediaItemIndex to get the window of the media item currently being played.
ExoPlayer Version
1.3.1
Question
I am working with a live HLS stream and need to obtain information about the last segment that has been added to the playlist (
m3u8
) without directly reading the manifest from ExoPlayer.Context
Here is an example of an HLS manifest (
m3u8
) I am working with:Problem
I need to detect when a new segment has been loaded into the playlist and get information about it, but without directly analyzing the manifest from the code. In other words, I want to know when ExoPlayer detects and loads a new segment during real-time playback.
Specific Questions:
Any guidance or examples would be greatly appreciated. Thanks in advance!
The text was updated successfully, but these errors were encountered: