0

I am building a browser songs personalized application. I am in the starting phase of the application where I want to click a button and change the song currently being played by the audio player in HTML5. I wanted to know how can I change the source of the audio. I tried using a ajax call when the button is clicked and then the following commands

var audio= document.getElementById("myplayer");
audio.src="E:/My Collection/abcd.mp3"; 

But this doesn't work and the same audio song continues. Can anyone help me with this. Thank You.

user1580096
  • 487
  • 1
  • 7
  • 17
  • The big problem with your code is that the browser is not going to let you load a local file like that: http://stackoverflow.com/questions/371875/local-file-access-with-javascript – steveax Aug 15 '13 at 07:59

2 Answers2

1

Take the list of your audio file in an array.

var audioArr = new Array(); audioArr = ["abc.mp3", "xyz.mp3"];

And, then onclick() of button you can pass index. Eg: audio.src = audioArr[index];

I hope this works :)

1

in addition to what Bhavya said about array, add audio.load(); or audio.play(); after changing the src. it would make the audio tag reload.