Fix HLS cleanup
This commit is contained in:
12
index.js
12
index.js
@@ -104,15 +104,20 @@ var hls = null;
|
|||||||
var currentVideo = 0;
|
var currentVideo = 0;
|
||||||
|
|
||||||
const changeVid = index => {
|
const changeVid = index => {
|
||||||
var oldSelectedVideo = document.querySelector(`#playlistEntry${currentVideo}`);
|
let oldSelectedVideo = document.querySelector(`#playlistEntry${currentVideo}`);
|
||||||
oldSelectedVideo.classList.remove("bg-dark");
|
oldSelectedVideo.classList.remove("bg-dark");
|
||||||
oldSelectedVideo.classList.remove("text-light");
|
oldSelectedVideo.classList.remove("text-light");
|
||||||
|
if(!hls==null) {
|
||||||
|
console.log("Removing HLS.js");
|
||||||
|
hls.detachMedia(vidPlayer);
|
||||||
|
hls = null;
|
||||||
|
}
|
||||||
|
|
||||||
console.log("Switching video to index", index);
|
console.log("Switching video to index", index);
|
||||||
titleText.innerHTML = vids[index].name;
|
titleText.innerHTML = vids[index].name;
|
||||||
currentVideo = index;
|
currentVideo = index;
|
||||||
|
|
||||||
var newSelectedVideo = document.querySelector(`#playlistEntry${currentVideo}`)
|
let newSelectedVideo = document.querySelector(`#playlistEntry${currentVideo}`)
|
||||||
newSelectedVideo.classList.add("bg-dark");
|
newSelectedVideo.classList.add("bg-dark");
|
||||||
newSelectedVideo.classList.add("text-light");
|
newSelectedVideo.classList.add("text-light");
|
||||||
|
|
||||||
@@ -120,9 +125,6 @@ const changeVid = index => {
|
|||||||
Hls.isSupported() &&
|
Hls.isSupported() &&
|
||||||
vids[index].url.endsWith(".m3u8")) {
|
vids[index].url.endsWith(".m3u8")) {
|
||||||
console.log("Using HLS.js");
|
console.log("Using HLS.js");
|
||||||
if(!hls==null) {
|
|
||||||
hls.detachMedia(vidPlayer);
|
|
||||||
}
|
|
||||||
hls = new Hls();
|
hls = new Hls();
|
||||||
hls.loadSource(vids[index].url);
|
hls.loadSource(vids[index].url);
|
||||||
hls.attachMedia(vidPlayer);
|
hls.attachMedia(vidPlayer);
|
||||||
|
|||||||
Reference in New Issue
Block a user