switch to let from var, switch to fetch from XHR
This commit is contained in:
parent
f4c54fc43c
commit
103d47b9d7
1 changed files with 9 additions and 15 deletions
|
@ -9,23 +9,17 @@ class PlaylistLoader {
|
|||
this.fetch_playlist();
|
||||
}
|
||||
|
||||
fetch_playlist() {
|
||||
var xmlHttp = new XMLHttpRequest();
|
||||
xmlHttp.onreadystatechange = ( function() {
|
||||
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
|
||||
this.parse_playlist(xmlHttp.responseText);
|
||||
setTimeout(this.fetch_playlist.bind(this), this.refresh_interval * 1000);
|
||||
}
|
||||
} ).bind(this)
|
||||
xmlHttp.open("GET", this.playlist_src, true);
|
||||
xmlHttp.send(null);
|
||||
async fetch_playlist() {
|
||||
const response = await fetch(this.playlist_src);
|
||||
this.parse_playlist(await response.text());
|
||||
setTimeout(this.fetch_playlist.bind(this), this.refresh_interval * 1000);
|
||||
}
|
||||
|
||||
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++) {
|
||||
let lines = playlist_content.split('\n');
|
||||
let segments = [];
|
||||
let segment_block_flag = this.last_segment === null ? false : true;
|
||||
for (let 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]);
|
||||
|
@ -45,4 +39,4 @@ class PlaylistLoader {
|
|||
}
|
||||
}
|
||||
|
||||
var test = new PlaylistLoader();
|
||||
let test = new PlaylistLoader();
|
||||
|
|
Loading…
Reference in a new issue