m3u8 parsing and segment fetch queue
This commit is contained in:
parent
1688b36e39
commit
4be364ce2e
1 changed files with 27 additions and 3 deletions
|
@ -7,16 +7,40 @@ class PlaylistLoader {
|
||||||
this.refresh_interval = null;
|
this.refresh_interval = null;
|
||||||
this.new_segments = [];
|
this.new_segments = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_playlist() {
|
fetch_playlist() {
|
||||||
var xmlHttp = new XMLHttpRequest();
|
var xmlHttp = new XMLHttpRequest();
|
||||||
xmlHttp.onreadystatechange = function() {
|
xmlHttp.onreadystatechange = ( function() {
|
||||||
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
|
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
|
||||||
console.log(xmlHttp.responseText);
|
this.parse_playlist(xmlHttp.responseText);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} ).bind(this)
|
||||||
xmlHttp.open("GET", this.playlist_src, true);
|
xmlHttp.open("GET", this.playlist_src, true);
|
||||||
xmlHttp.send(null);
|
xmlHttp.send(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parse_playlist(playlist_content) {
|
||||||
|
var lines = playlist_content.split('\n');
|
||||||
|
var segments = [];
|
||||||
|
var segment_block_flag = this.last_segment === null ? false : true;
|
||||||
|
for (var i = 0; i < lines.length; i++) {
|
||||||
|
if (lines[i].startsWith("#")) {
|
||||||
|
if (lines[i].startsWith("EXT-X-TARGETDURATION", 1)) {
|
||||||
|
this.refresh_interval = parseFloat(lines[i].split(':')[1]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (segment_block_flag || lines[i] == '') {
|
||||||
|
if (lines[i] == this.last_segment) {
|
||||||
|
segment_block_flag = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
segments.push(lines[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.new_segments = segments;
|
||||||
|
this.last_segment = segments.at(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var test = new PlaylistLoader();
|
var test = new PlaylistLoader();
|
||||||
|
|
Loading…
Reference in a new issue