2023-08-22 15:44:32 +05:00
|
|
|
var player = document.getElementById('vid1');
|
|
|
|
|
|
|
|
class PlaylistLoader {
|
|
|
|
constructor() {
|
|
|
|
this.playlist_src = '/list/' + window.location.pathname.slice(6);
|
|
|
|
this.last_segment = null;
|
|
|
|
this.refresh_interval = null;
|
|
|
|
this.new_segments = [];
|
|
|
|
}
|
2023-08-22 18:20:09 +05:00
|
|
|
|
2023-08-22 15:44:32 +05:00
|
|
|
fetch_playlist() {
|
|
|
|
var xmlHttp = new XMLHttpRequest();
|
2023-08-22 18:20:09 +05:00
|
|
|
xmlHttp.onreadystatechange = ( function() {
|
2023-08-22 15:44:32 +05:00
|
|
|
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
|
2023-08-22 18:20:09 +05:00
|
|
|
this.parse_playlist(xmlHttp.responseText);
|
2023-08-22 15:44:32 +05:00
|
|
|
}
|
2023-08-22 18:20:09 +05:00
|
|
|
} ).bind(this)
|
2023-08-22 15:44:32 +05:00
|
|
|
xmlHttp.open("GET", this.playlist_src, true);
|
|
|
|
xmlHttp.send(null);
|
|
|
|
}
|
2023-08-22 18:20:09 +05:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2023-08-22 15:44:32 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
var test = new PlaylistLoader();
|
|
|
|
test.fetch_playlist()
|