WIP: Investigating audio context and player issues
This commit is contained in:
@@ -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
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user