Skip to content

Commit

Permalink
feat: Use ll-hls query directives and support skipping segments
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Mar 3, 2021
1 parent c3951b2 commit e587c92
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ export const updateMaster = (master, media, unchangedCheck = isPlaylistUnchanged

media.segments = media.segments || [];

// add any skipped segments back onto the front
// so that they can be carried to the new playlist.
if (media.skip) {
const segments = [];

segments.length = media.skip.skippedSegments;

media.segments = segments.concat(media.segments);
}

// a preloadSegment with only preloadHints is not currently
// a usable segment, only include a preloadSegment that has
// parts.
Expand Down Expand Up @@ -227,11 +237,35 @@ export default class PlaylistLoader extends EventTarget {
// only refresh the media playlist if no other activity is going on
return;
}
const media = this.media();

let uri = resolveUrl(this.master.uri, media.uri);
const query = [];

// TODO: check CAN skip until to verify we can skip until x segment
// wait for the next part/segment
if (media.serverControl.canBlockReload) {
const preloadSegment = media.preloadSegment;

if (preloadSegment && preloadSegment.preloadHints) {
query.push(`_HLS_part=${(preloadSegment.parts && preloadSegment.parts.length || 0) + preloadSegment.preloadHints.length}`);
}
query.push(`_HLS_msn=${media.mediaSequence + media.segments.length - 1}`);
}

if (media.serverControl.canSkipUntil) {
query.push('_HLS_skip=YES');
}

query.forEach(function(str, i) {
const symbol = i === 0 ? '?' : '&';

uri += `${symbol}${str}`;
});
this.state = 'HAVE_CURRENT_METADATA';

this.request = this.vhs_.xhr({
uri: resolveUrl(this.master.uri, this.media().uri),
uri,
withCredentials: this.withCredentials
}, (error, req) => {
// disposed
Expand Down

0 comments on commit e587c92

Please sign in to comment.