<Audio> Play next song | Sololearn: Learn to code for FREE!

+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

7/16/2017 1:49:38 PM

Limitless

8 Answers

New Answer

+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

+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

+4

lol, works meow

+2

line 5 cannot read indexOf of undefined... @Limitless it don't work yet? Aww

+2

did u put it on a different code? I still get same errors

+1

Thanks Maz, you're a true Angel!

+1

Thanks to Maz's help, I've learned out of these mistakes @Russel Reeder But it's working now, thanks :)

+1

Oh I forgot to update it ๐Ÿ˜‚