Feat: Auto-play on skip & Gotify notifications

This commit is contained in:
Hördle Bot
2025-11-22 10:34:22 +01:00
parent 4f8524c286
commit f8fb3ccf69
4 changed files with 75 additions and 7 deletions

View File

@@ -6,9 +6,10 @@ interface AudioPlayerProps {
src: string;
unlockedSeconds: number; // 2, 4, 7, 11, 16, 30 (or full length)
onPlay?: () => void;
autoPlay?: boolean;
}
export default function AudioPlayer({ src, unlockedSeconds, onPlay }: AudioPlayerProps) {
export default function AudioPlayer({ src, unlockedSeconds, onPlay, autoPlay = false }: AudioPlayerProps) {
const audioRef = useRef<HTMLAudioElement>(null);
const [isPlaying, setIsPlaying] = useState(false);
const [progress, setProgress] = useState(0);
@@ -19,8 +20,23 @@ export default function AudioPlayer({ src, unlockedSeconds, onPlay }: AudioPlaye
audioRef.current.currentTime = 0;
setIsPlaying(false);
setProgress(0);
if (autoPlay) {
const playPromise = audioRef.current.play();
if (playPromise !== undefined) {
playPromise
.then(() => {
setIsPlaying(true);
onPlay?.();
})
.catch(error => {
console.log("Autoplay prevented:", error);
setIsPlaying(false);
});
}
}
}
}, [src, unlockedSeconds]);
}, [src, unlockedSeconds, autoPlay]);
const togglePlay = () => {
if (!audioRef.current) return;