html5 - How to change Javascript audio object src? -


i'm creating custom html5 audio player. have following snippet in script.

var curaudio = new audio('audio.mp3'); $("#play").on("click", function(e) {     e.preventdefault();     curaudio.play(); }); $("#next").on("click", function(e) {     e.preventdefault();     [update curaudio src here]     curaudio.play(); }); 

this snippet highly simplified , isn't practical enough question is, how update src of audio object dynamically? if use

var curaudio = $("#audio"); 

i can change src using

curaudio.attr("src", "newaudio.mp3"); 

but how do former method?

you can set different source element's src property:

curaudio.src = 'http://.../newaudio.mp3'; 

this .prop() accomplishes jquery collections:

$("#audio").prop('src', 'http://.../newaudio.mp3'); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -