added custom sound and sound test button in admin panel
This commit is contained in:
@@ -526,6 +526,7 @@
|
|||||||
<button class="btn btn-warning btn-small" onclick="clearLog()">Clear Log</button>
|
<button class="btn btn-warning btn-small" onclick="clearLog()">Clear Log</button>
|
||||||
<button class="btn btn-warning btn-small" onclick="resetDay()">Reset Daily Limit</button>
|
<button class="btn btn-warning btn-small" onclick="resetDay()">Reset Daily Limit</button>
|
||||||
<button class="btn btn-danger btn-small" onclick="resetAllPoints()">Reset All</button>
|
<button class="btn btn-danger btn-small" onclick="resetAllPoints()">Reset All</button>
|
||||||
|
<button class="btn btn-warning btn-small" onclick="testAudio()">Test Audio</button>
|
||||||
<button class="btn btn-primary btn-small" onclick="exitAdminMode()">Exit Admin</button>
|
<button class="btn btn-primary btn-small" onclick="exitAdminMode()">Exit Admin</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1313,51 +1314,84 @@
|
|||||||
let audioPlaying = false;
|
let audioPlaying = false;
|
||||||
|
|
||||||
function startAlarmSound() {
|
function startAlarmSound() {
|
||||||
|
console.log('Starting alarm sound...');
|
||||||
const audioElement = document.getElementById('timerAudio');
|
const audioElement = document.getElementById('timerAudio');
|
||||||
|
|
||||||
|
// Force load the audio
|
||||||
|
audioElement.load();
|
||||||
|
|
||||||
|
// Set volume to max
|
||||||
|
audioElement.volume = 1.0;
|
||||||
audioElement.loop = true;
|
audioElement.loop = true;
|
||||||
audioElement.play().catch(error => {
|
|
||||||
console.log('Audio playback failed:', error);
|
// Try to play
|
||||||
// Fallback - try to create a beep sound
|
const playPromise = audioElement.play();
|
||||||
createBeepSound();
|
|
||||||
});
|
if (playPromise !== undefined) {
|
||||||
audioPlaying = true;
|
playPromise
|
||||||
|
.then(() => {
|
||||||
|
console.log('Audio playing successfully');
|
||||||
|
audioPlaying = true;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Audio playback failed:', error);
|
||||||
|
console.log('Audio src:', audioElement.src);
|
||||||
|
console.log('Audio readyState:', audioElement.readyState);
|
||||||
|
console.log('Audio error:', audioElement.error);
|
||||||
|
|
||||||
|
// Try fallback beep
|
||||||
|
createBeepSound();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopAlarmSound() {
|
function stopAlarmSound() {
|
||||||
|
console.log('Stopping alarm sound...');
|
||||||
const audioElement = document.getElementById('timerAudio');
|
const audioElement = document.getElementById('timerAudio');
|
||||||
audioElement.pause();
|
audioElement.pause();
|
||||||
audioElement.currentTime = 0;
|
audioElement.currentTime = 0;
|
||||||
audioPlaying = false;
|
audioPlaying = false;
|
||||||
|
|
||||||
|
// Stop any fallback beep
|
||||||
|
if (window.audioContext) {
|
||||||
|
window.audioContext.close();
|
||||||
|
window.audioContext = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function playCompletionSound() {
|
function playCompletionSound() {
|
||||||
// Single play for non-alarm situations
|
console.log('Playing completion sound (single)...');
|
||||||
const audioElement = document.getElementById('timerAudio');
|
const audioElement = document.getElementById('timerAudio');
|
||||||
audioElement.loop = false;
|
audioElement.loop = false;
|
||||||
|
audioElement.volume = 1.0;
|
||||||
audioElement.play().catch(error => {
|
audioElement.play().catch(error => {
|
||||||
console.log('Audio playback failed:', error);
|
console.error('Single play failed:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createBeepSound() {
|
function createBeepSound() {
|
||||||
// Fallback beep using Web Audio API
|
console.log('Creating fallback beep sound...');
|
||||||
try {
|
try {
|
||||||
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
window.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
const oscillator = audioContext.createOscillator();
|
const oscillator = window.audioContext.createOscillator();
|
||||||
const gainNode = audioContext.createGain();
|
const gainNode = window.audioContext.createGain();
|
||||||
|
|
||||||
oscillator.connect(gainNode);
|
oscillator.connect(gainNode);
|
||||||
gainNode.connect(audioContext.destination);
|
gainNode.connect(window.audioContext.destination);
|
||||||
|
|
||||||
oscillator.frequency.value = 800; // Frequency in Hz
|
oscillator.frequency.value = 800; // Frequency in Hz
|
||||||
|
oscillator.type = 'sine';
|
||||||
gainNode.gain.value = 0.3; // Volume
|
gainNode.gain.value = 0.3; // Volume
|
||||||
|
|
||||||
oscillator.start();
|
oscillator.start();
|
||||||
|
audioPlaying = true;
|
||||||
|
|
||||||
// Create beeping pattern
|
// Create beeping pattern
|
||||||
const beepPattern = () => {
|
const beepPattern = () => {
|
||||||
if (!audioPlaying) {
|
if (!audioPlaying) {
|
||||||
oscillator.stop();
|
oscillator.stop();
|
||||||
|
window.audioContext.close();
|
||||||
|
window.audioContext = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gainNode.gain.value = gainNode.gain.value > 0 ? 0 : 0.3;
|
gainNode.gain.value = gainNode.gain.value > 0 ? 0 : 0.3;
|
||||||
@@ -1365,16 +1399,63 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
beepPattern();
|
beepPattern();
|
||||||
|
console.log('Beep sound started');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Web Audio API not supported');
|
console.error('Web Audio API error:', e);
|
||||||
|
// Last resort - use notification API if available
|
||||||
|
if ('Notification' in window && Notification.permission === 'granted') {
|
||||||
|
new Notification('Timer Complete!', {
|
||||||
|
body: 'Your timer has finished.',
|
||||||
|
requireInteraction: true
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test audio on page load
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
const audioElement = document.getElementById('timerAudio');
|
||||||
|
console.log('Audio element found:', audioElement);
|
||||||
|
console.log('Audio sources:', audioElement.getElementsByTagName('source').length);
|
||||||
|
|
||||||
|
// Check if audio can play
|
||||||
|
audioElement.addEventListener('canplay', () => {
|
||||||
|
console.log('Audio can play');
|
||||||
|
});
|
||||||
|
|
||||||
|
audioElement.addEventListener('error', (e) => {
|
||||||
|
console.error('Audio error event:', e);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Request notification permission for fallback
|
||||||
|
if ('Notification' in window && Notification.permission === 'default') {
|
||||||
|
Notification.requestPermission();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function dismissTimerComplete() {
|
function dismissTimerComplete() {
|
||||||
stopAlarmSound();
|
stopAlarmSound();
|
||||||
closeModal('timerCompleteModal');
|
closeModal('timerCompleteModal');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test audio function
|
||||||
|
function testAudio() {
|
||||||
|
console.log('Testing audio...');
|
||||||
|
startAlarmSound();
|
||||||
|
|
||||||
|
// Show test modal
|
||||||
|
showAlert('Testing audio alarm. Click OK to stop.', 'Audio Test');
|
||||||
|
|
||||||
|
// Override OK button to stop sound
|
||||||
|
setTimeout(() => {
|
||||||
|
const okButton = document.querySelector('#alertModal button');
|
||||||
|
okButton.onclick = () => {
|
||||||
|
stopAlarmSound();
|
||||||
|
closeModal('alertModal');
|
||||||
|
};
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
// Close modals when clicking outside (except for no-close modals)
|
// Close modals when clicking outside (except for no-close modals)
|
||||||
window.onclick = function(event) {
|
window.onclick = function(event) {
|
||||||
const modals = document.querySelectorAll('.modal:not(.no-close)');
|
const modals = document.querySelectorAll('.modal:not(.no-close)');
|
||||||
|
BIN
public/timer-complete.mp3
Normal file
BIN
public/timer-complete.mp3
Normal file
Binary file not shown.
Reference in New Issue
Block a user