mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-07-30 00:39:16 +02:00
Prevent the volume from remaining the same when the player is paused with the volume at zero If you pause the player, reset the volume and play it again, you will see that the player will have the volume at 100% for a moment
70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
let Stream;
|
|
let shouldReconnect = true;
|
|
let newVolumeGlobal = 1;
|
|
|
|
function Init(_ev) {
|
|
$(".playbutton").off('click').on('click', OnPlayButtonClick); // Ensure only one event handler is attached
|
|
$("#volumeSlider").off("input").on("input", updateVolume); // Ensure only one event handler is attached
|
|
}
|
|
|
|
function createStream() {
|
|
try {
|
|
const settings = new _3LAS_Settings();
|
|
Stream = new _3LAS(null, settings);
|
|
Stream.Volume = $('#volumeSlider').val();
|
|
Stream.ConnectivityCallback = OnConnectivityCallback;
|
|
} catch (error) {
|
|
console.error("Initialization Error: ", error);
|
|
}
|
|
}
|
|
|
|
function destroyStream() {
|
|
if (Stream) {
|
|
Stream.Stop();
|
|
Stream = null;
|
|
}
|
|
}
|
|
|
|
function OnConnectivityCallback(isConnected) {
|
|
console.log("Connectivity changed:", isConnected);
|
|
if (Stream) {
|
|
Stream.Volume = $('#volumeSlider').val();
|
|
} else {
|
|
console.warn("Stream is not initialized.");
|
|
}
|
|
}
|
|
|
|
function OnPlayButtonClick(_ev) {
|
|
const $playbutton = $('.playbutton');
|
|
if (Stream) {
|
|
console.log("Stopping stream...");
|
|
shouldReconnect = false;
|
|
destroyStream();
|
|
$playbutton.find('.fa-solid').toggleClass('fa-stop fa-play');
|
|
} else {
|
|
console.log("Starting stream...");
|
|
shouldReconnect = true;
|
|
createStream();
|
|
Stream.Start();
|
|
$playbutton.find('.fa-solid').toggleClass('fa-play fa-stop');
|
|
}
|
|
$playbutton.addClass('bg-gray').prop('disabled', true);
|
|
setTimeout(() => {
|
|
$playbutton.removeClass('bg-gray').prop('disabled', false);
|
|
}, 3000);
|
|
}
|
|
|
|
function updateVolume() {
|
|
if (Stream) {
|
|
const newVolume = $(this).val();
|
|
newVolumeGlobal = newVolume;
|
|
console.log("Volume updated to:", newVolume);
|
|
Stream.Volume = newVolume;
|
|
} else {
|
|
console.warn("Stream is not initialized.");
|
|
}
|
|
}
|
|
|
|
$(document).ready(Init);
|
|
|