+ 2

<Audio> Play next song

I recently saw a question that asked how we could play the next song once it has stopped, and after doing research I found an idea on what should or could happen, but as a good old saying says: Once a question has been answered new questions arrises. I am receiving a typeError in JS on line 5 and I believe that it is from the Array that I've set. I would like to know if the links that I've set in the array could cause the problem? https://code.sololearn.com/WGej0A40n3tA/?ref=app

16th Jul 2017, 1:49 PM
Limitless
Limitless - avatar
8 Réponses
+ 16
1. You're using jQuery and Pure JS in the same document making different things, to make it very simple... conflict. 2. The addEventListener take an event and a callback as mandatory parameters, the callback should be written without the parenthesis, so... use: audio.addEventListener("ended",Switch); ... rather than: audio.addEventListener("ended",Switch()); 3. The "onload" events are your friends. I re-wrote the code in pure JS, not big differences and this should solve your problem (maybe), i'm pretty busy at the moment and in addition for magic reasons i can't access to my notification panel and see if you'll answer here, so... sorry from now if i won't answer anymore in this thread. :3 Take this as a reference: https://code.sololearn.com/WLjhCwWsF8fc/?ref=app
16th Jul 2017, 2:30 PM
Maz
Maz - avatar
+ 4
You can also use this audio.addEventListener("ended", function() { // callback function here }); this way you can preserve some line of the code also without getting confused that whether to use "Switch()" or simply "Switch" as the callback parameter of the addEventListener method
16th Jul 2017, 2:44 PM
Siddharth Saraf
+ 4
lol, works meow
16th Jul 2017, 9:22 PM
Russel Reeder
Russel Reeder - avatar
+ 2
line 5 cannot read indexOf of undefined... @Limitless it don't work yet? Aww
16th Jul 2017, 7:28 PM
Russel Reeder
Russel Reeder - avatar
+ 2
did u put it on a different code? I still get same errors
16th Jul 2017, 8:55 PM
Russel Reeder
Russel Reeder - avatar
+ 1
Thanks Maz, you're a true Angel!
16th Jul 2017, 3:22 PM
Limitless
Limitless - avatar
+ 1
Thanks to Maz's help, I've learned out of these mistakes @Russel Reeder But it's working now, thanks :)
16th Jul 2017, 8:52 PM
Limitless
Limitless - avatar
+ 1
Oh I forgot to update it ūüėā
16th Jul 2017, 9:11 PM
Limitless
Limitless - avatar