Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot replacement audio source #4009

Closed
SmirnovMaxim opened this issue Jan 24, 2025 · 6 comments · Fixed by #4010
Closed

Hot replacement audio source #4009

SmirnovMaxim opened this issue Jan 24, 2025 · 6 comments · Fixed by #4010
Labels

Comments

@SmirnovMaxim
Copy link

Bug description

There are several tracks in the form of a playlist, they should play one after another. However, now when changing a track, the previous one plays. The problem is solved only by pausing and then playing again.

Environment

  • Browser: Chrome

Minimal code snippet

https://codepen.io/SmirnovMaxim/pen/jENQyro

Expected result

After call load(...) the new track is playing

Obtained result

After call load(...) the old track is playing

Screenshots

@katspaugh
Copy link
Owner

katspaugh commented Jan 24, 2025

Thanks! That's a weird bug. Looks like the previous URL is cached somewhere internally and isn't cleared properly on load.
Edit: The waveform does change so it looks like it's stuck somewhere in the media element.

@SmirnovMaxim
Copy link
Author

I think it's some race condition - when I'm debugging in DevTools this behavior step by step the new track is playing.

@katspaugh
Copy link
Owner

katspaugh commented Jan 24, 2025

I fixed it in your codepen by resetting the audio element like so:

document.querySelector("#next").addEventListener("click", () => {
  index = index === 0 ? 1 : 0;
  wavesurfer.stop()
  
  wavesurfer.getMediaElement().src = ''
  wavesurfer.load(list[index]);
});

Also it starts switching the audio after you press Next a second time, so maybe you're seeing this?

@SmirnovMaxim
Copy link
Author

SmirnovMaxim commented Jan 24, 2025

I tried it but doesn't work

P.S. Codepen has been updated

@katspaugh
Copy link
Owner

For me, it now works when the track finishes and automatically switches to the next one.
The next button doesn't fully work – it briefly switches to the next audio and then back to the previous one. Probably because it triggers a finish event, so it switches twice.

@SmirnovMaxim
Copy link
Author

Yeah, it works, thanks so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants