improve console.log

This commit is contained in:
deflax 2024-09-08 01:29:31 +00:00
parent 566bb34603
commit cb5d4140a5

View file

@ -81,35 +81,34 @@ document.addEventListener('DOMContentLoaded', () => {
// Check if the response is successful (status code 200)
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
throw new Error(`HLS.js: HTTP error! Status: ${response.status}`);
}
// Parse JSON from the response
const data = await response.json();
// Now 'data' contains the parsed JSON
console.log("Fetched JSON data:", data);
// console.log("Fetched JSON data:", data);
const oldsrc = hls.url;
const newsrc = data.head;
if (newsrc === oldsrc) {
//console.log(oldsrc);
//console.log(newsrc);
console.log('HLS.js: playing from ' newsrc);
} else {
console.log('playhead: switching to ' + newsrc)
console.log('HLS.js: switching to ' + newsrc)
hls.loadSource(newsrc);
video.load(); // Reload the video element to apply the new source
video.play().catch(error => {
console.error('Autoplay was prevented:', error);
console.error('HLS.js: Autoplay was prevented:', error);
});
}
} catch (error) {
console.error("Error fetching data:", error);
console.error("HLS.js: Error fetching data:", error);
}
}
fetchData();
// Set the interval for periodic execution (e.g., every 5 seconds)
const interval = 4200; // in milliseconds
setInterval(fetchData, interval);
@ -122,7 +121,7 @@ document.addEventListener('DOMContentLoaded', () => {
// all available video qualities. This is important; in this approach,
// we will have one source on the Plyr player.
hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
console.log('hls: manifest parsed');
console.log('HLS.js: manifest parsed');
// Transform available levels into an array of integers (height values).
const availableQualities = hls.levels.map((l) => l.height)
@ -144,7 +143,7 @@ document.addEventListener('DOMContentLoaded', () => {
}
hls.on(Hls.Events.LEVEL_SWITCHED, function (event, data) {
console.log('hls: level switched');
console.log('HLS.js: level switched');
var span = document.querySelector(".plyr__menu__container [data-plyr='quality'][value='0'] span")
if (hls.autoLevelEnabled) {
span.innerHTML = `AUTO (${hls.levels[data.level].height}p)`
@ -169,19 +168,21 @@ document.addEventListener('DOMContentLoaded', () => {
// Check if the response is successful (status code 200)
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
throw new Error(`Video: HTTP error! Status: ${response.status}`);
}
// Parse JSON from the response
const data = await response.json();
// Now 'data' contains the parsed JSON
console.log("Fetched JSON data:", data);
//console.log("Fetched JSON data:", data);
video.src = data.head;
console.log('Video: switching to ', data.head)
const player = new Plyr(video, defaultOptions);
} catch (error) {
console.error("Error fetching data:", error);
console.error("Video: Error fetching data:", error);
}
}
fetchInitData();
@ -193,7 +194,7 @@ document.addEventListener('DOMContentLoaded', () => {
} else {
window.hls.levels.forEach((level, levelIndex) => {
if (level.height === newQuality) {
console.log("hls: Found quality match with " + newQuality);
console.log("HLS.js: Found quality match with " + newQuality);
window.hls.currentLevel = levelIndex;
}
});