0

I'm trying to recreate this HTML5 player, but even if I copy/paste the code, I still get errors.

The first error I fixed by changeing audio[0].volume = .10; to this audio[0] = { volume : .10 };

But this next one I can't fix: audio[0].addEventListener("ended",function(e){

So now, when I click another tracktitle it just opens the url :(

The Fiddle works fine! http://jsfiddle.net/lastrose/vkMqR/

Can anyone help??

MadsRH
  • 1
  • 5
  • I would guess that the error shown for `audio[0].volume = .10;` was that you cant set `volume` for `undefined`, is that correct. With `audio[0] = { volume : .10 };` you set `auto[0]` to an object, as of that this one does not have a function `addEventListener`. – t.niese Apr 11 '16 at 06:59
  • Errors in fiddle code here you don't need to add index in `run()` for `audio[0].load();audio[0].play();` just is required `audio.load();audio.play();` because we passed `audio[0]` to function; – itzmukeshy7 Apr 11 '16 at 07:00
  • @t.niese correct, but do you mean that that was wrong? or should I have done the same for addEventListener ? – MadsRH Apr 11 '16 at 09:48
  • No the `audio[0] = { volume : .10 };` itself is wrong. It has to be `audio[0].volume = .10;`. At the time you call `init` the `audio` is not in the DOM. You need to load your script either at the end of the `body` or use the dom ready event ([Why does jQuery or a DOM method such as getElementById not find the element?](http://stackoverflow.com/questions/14028959) , [jQuery is not finding elements](http://stackoverflow.com/questions/12301605)). – t.niese Apr 11 '16 at 09:53
  • @t.niese moved the script after the HTML5 code, and it worked perfectly :D Thanks – MadsRH Apr 12 '16 at 07:40
  • Don't know if I should create a new thread, but can you also help me start autoplay when the page is loaded? – MadsRH Apr 12 '16 at 07:49
  • @MadsRH Your really should do a search before asking: [Playing audio after the page loads in html](http://stackoverflow.com/questions/14356956) – t.niese Apr 12 '16 at 08:31

0 Answers0