WIP: Working on player
This commit is contained in:
21
web/src/hooks/useWaveform.ts
Normal file → Executable file
21
web/src/hooks/useWaveform.ts
Normal file → Executable file
@@ -45,25 +45,16 @@ export function useWaveform(
|
||||
|
||||
useEffect(() => {
|
||||
if (!containerRef.current) {
|
||||
console.debug('useWaveform: container ref is null, skipping initialization');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!options.url || options.url === 'null' || options.url === 'undefined') {
|
||||
console.debug('useWaveform: invalid URL, skipping initialization', { url: options.url });
|
||||
return;
|
||||
}
|
||||
|
||||
console.debug('useWaveform: initializing audio service', {
|
||||
url: options.url,
|
||||
songId: options.songId,
|
||||
bandId: options.bandId,
|
||||
containerExists: !!containerRef.current
|
||||
});
|
||||
|
||||
const initializeAudio = async () => {
|
||||
try {
|
||||
console.debug('useWaveform: using audio service instance');
|
||||
|
||||
|
||||
await audioService.initialize(containerRef.current!, options.url!);
|
||||
|
||||
@@ -105,7 +96,7 @@ export function useWaveform(
|
||||
globalBandId === options.bandId &&
|
||||
globalIsPlaying) {
|
||||
|
||||
console.debug('useWaveform: restoring playback state');
|
||||
|
||||
|
||||
// Wait a moment for the waveform to be ready
|
||||
setTimeout(() => {
|
||||
@@ -120,7 +111,7 @@ export function useWaveform(
|
||||
options.onReady?.(audioService.getDuration());
|
||||
|
||||
return () => {
|
||||
console.debug('useWaveform: cleanup');
|
||||
|
||||
unsubscribe();
|
||||
// Note: We don't cleanup the audio service here to maintain persistence
|
||||
// audioService.cleanup();
|
||||
@@ -138,7 +129,7 @@ export function useWaveform(
|
||||
}, [options.url, options.songId, options.bandId, containerRef, currentSongId, globalBandId, globalCurrentTime, globalIsPlaying, setCurrentSong]);
|
||||
|
||||
const play = () => {
|
||||
console.debug('useWaveform.play called');
|
||||
|
||||
try {
|
||||
audioService.play();
|
||||
} catch (error) {
|
||||
@@ -147,7 +138,7 @@ export function useWaveform(
|
||||
};
|
||||
|
||||
const pause = () => {
|
||||
console.debug('useWaveform.pause called');
|
||||
|
||||
try {
|
||||
audioService.pause();
|
||||
} catch (error) {
|
||||
@@ -156,7 +147,7 @@ export function useWaveform(
|
||||
};
|
||||
|
||||
const seekTo = (time: number) => {
|
||||
console.debug('useWaveform.seekTo called', { time });
|
||||
|
||||
try {
|
||||
if (isReady && isFinite(time)) {
|
||||
audioService.seekTo(time);
|
||||
|
||||
Reference in New Issue
Block a user