WIP: Investigating audio context and player issues

This commit is contained in:
Mistral Vibe
2026-04-08 18:38:28 +02:00
parent 9c032d0774
commit 9c4c3cda34
3 changed files with 126 additions and 85 deletions

View File

@@ -107,9 +107,16 @@ export function useWaveform(
const checkReady = setInterval(() => {
if (audioService.getDuration() > 0) {
clearInterval(checkReady);
audioService.play(options.songId, options.bandId);
if (globalCurrentTime > 0) {
audioService.seekTo(globalCurrentTime);
// Only attempt to play if we have a valid audio context
// This prevents autoplay policy violations
try {
audioService.play(options.songId, options.bandId);
if (globalCurrentTime > 0) {
audioService.seekTo(globalCurrentTime);
}
} catch (error) {
console.warn('Auto-play prevented by browser policy, waiting for user gesture:', error);
// Don't retry - wait for user to click play
}
}
}, 50);
@@ -138,11 +145,19 @@ export function useWaveform(
}, [options.url, options.songId, options.bandId, containerRef, currentSongId, globalBandId, globalCurrentTime, globalIsPlaying, setCurrentSong]);
const play = () => {
try {
audioService.play(options.songId || null, options.bandId || null);
} catch (error) {
console.error('useWaveform.play failed:', error);
// Only attempt to play if waveform is ready
if (audioService.isWaveformReady()) {
try {
audioService.play(options.songId || null, options.bandId || null);
} catch (error) {
console.error('useWaveform.play failed:', error);
}
} else {
console.warn('Cannot play: waveform not ready', {
hasWavesurfer: !!audioService.isPlaying(),
duration: audioService.getDuration(),
url: options.url
});
}
};