Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Could I start playing video from second segment in first playlist calls? #6598

Open
pdemeu23 opened this issue Jul 31, 2024 · 6 comments
Labels

Comments

@pdemeu23
Copy link

What do you want to do with Hls.js?

I want to know how I can start playing a video from the second segment. I have a playlist.m3u8 file with two segments inside. I know how to detect which segment was loaded, but I need to intercept it and change to get next one.

image

In the photo, we can see my mock playlist.m3u8, and in the console at the bottom, we have segment logs showing the segment that was loaded. The objective is to get segment 509 instead of segment 508.

Could someone help me with this?
Could someone can help me, please?

What have you tried so far?

I try find some solution in doc but I fail, after that I try to change currentTime passing some seconds in future to try advance in future to get next segment, but I fail again, I don't know what I need to do to resolve my issue

@pdemeu23 pdemeu23 added Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. Question labels Jul 31, 2024
@robwalch
Copy link
Collaborator

robwalch commented Aug 2, 2024

Interrupt loading once the segment list is retrieved. Loading can be started at the start time of any segment in the list:

// begin loading playlists with a callback for the first variant playlist
// containing the last of segments (`details.fragments`):
const hls = new Hls({});
hls.loadSource('https://host/index.m3u8');
hls.attachMedia(hlsVideo);
hls.once(Hls.Events.LEVEL_UPDATED, (name, data) => {
  // set the start position using startLoad to skip loading of the first segment 
  const fragments = data.details.fragments;
  const startTime = fragments[1].start;
  hls.startLoad(startTime);
});

@robwalch robwalch removed the Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. label Aug 2, 2024
@pedro-demeu
Copy link

@robwalch

Hi, thanks so much! I've been working on a solution for that. I was able to fix it by changing the value of liveSyncDurationCount.

The value was 8, and I set it to 0, which made it start consuming the second segment from the first playlist exactly as I needed.

Now I'm wondering if my solution is the best approach, since your solution seems better. What do you think?

image

@robwalch
Copy link
Collaborator

robwalch commented Aug 5, 2024

I was able to fix it by changing the value of liveSyncDurationCount

I did not notice that you were working with a live playlist. Live playlists should be at least three segments long and liveSyncDurationCount should be set to at least three.

Alternatively, you can set liveSyncDuration to 2.5x the segment or target duration.

Those guidelines work best with 4-10 second target durations. If you insist on using two second segments, you should at least double the number of segments in your sliding window and hold back an addition segment to maintain steady playback.

@pedro-demeu
Copy link

pedro-demeu commented Aug 8, 2024

@robwalch
Sorry for the delay in responding; I have many Jira tickets to work on...

Live playlists should be at least three segments long and liveSyncDurationCount should be set to at least three.

Is there a best practices manual for configuration/delay that I can read?

Regarding holding an additional segment, I didn’t understand what you meant. Could you provide an example?

Thank you for your attention. ✋🏾

@robwalch
Copy link
Collaborator

robwalch commented Aug 9, 2024

hold back an addition segment

I mean hold back the playhead one additional segment duration from the end of the playlist.

So if you have 2 second segments, the playlist should be at least 6 segments long and playback should start 3 or more segments from the end (as apposed to only 2.5).

@pedro-demeu
Copy link

Oh I got it!
Thanks again @robwalch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants