Updated audio playback and preloading logic to check for and handle returned promises from play() and load() methods. This prevents uncaught promise rejections in browsers where these methods may return undefined, improving reliability and error handling for notification sounds.
35 lines
715 B
TypeScript
35 lines
715 B
TypeScript
"use client"
|
|
|
|
import { useEffect } from "react"
|
|
|
|
/**
|
|
* Preloads the notification audio file to ensure it's ready when needed
|
|
*/
|
|
export function AudioPreloader() {
|
|
useEffect(() => {
|
|
// Preload the audio file
|
|
const audio = new Audio('/hohoho.mp3')
|
|
audio.preload = 'auto'
|
|
|
|
// Try to load it immediately
|
|
try {
|
|
const loadPromise = audio.load();
|
|
if (loadPromise !== undefined) {
|
|
loadPromise.catch(err => {
|
|
console.log('Audio preload failed (non-critical):', err)
|
|
});
|
|
}
|
|
} catch (err) {
|
|
console.log('Audio preload failed (non-critical):', err)
|
|
}
|
|
|
|
return () => {
|
|
// Cleanup
|
|
audio.src = ''
|
|
}
|
|
}, [])
|
|
|
|
return null
|
|
}
|
|
|