How to properly stop the song and load next if previous source is still playing?

I made a simple React player but the problem is that it doesn't change the song and keeps playing it. https://code.sololearn.com/W2hiznM6jEGc/?ref=app

6/16/2019 9:52:28 AM

ᐺ ! ᖇ † ᒪ

13 Answers

New Answer


https://code.sololearn.com/WgppELogkUYK/#js not perfect... would like to press play automatically


Calviղ Burey 4rontender Rull Deef 🐺 Gordon guys, what do u think?


Jax 1) "profanity"? wth? songs shouldn't be religious. through songs people express their feelings, not always happy 2) your player is buggy and much slower than mine 3) it drops an error while tapping " pause" 4) it doesn't solve my problem 5) it looks less stylish than mine 6) it doesn't work. When I try to play a song, I even don't hear it, I only see a new thumb of it


Oma Falk dk why but Jax's player doesn't work :/. It doesn't load songs


Oma Falk thanks for idea! At least it changes properly


Jax maybe that slow prevents u from hearing two songs simultaneously.


Gordon when I tap to play next song, new song isn't started, but old song plays instead. But yeah, thanks for advice about src


Gordon also, Controls aren't displayed properly in your code


Gordon try starting "sugar honey ice and tea", and, while playing, switch to next song without a pause and you'll see that next track doesn't start playing and pause button doesn't change too


Jax <audio> is supported on my phone. So it is too slow so I thought it doesn't work


Because you set the song url at line 73 const track = new Audio(songs[id].url) once only when creating the app. you need to use {{songs[id].url}} as attribute of Controls component to make it updated; alternatively, try updating track in prev() and next() here is a fix for your reference, in case you couldn't work out. https://code.sololearn.com/Wh5Uu2VSa2n6/?ref=app also, the prev and next button can't call setPlaying which belongs to Control, perhaps disable them if not paused.



hmmm, that's strange. the play button and the prev next buttons all look normal on my device. before playing the song, i can use next button to change song, and then the src is changed, so then pressing play button will play the newly chosen song. my edition are at my line 75 79 80 84 85. you can add track.play() after src change.