I've got an audio object on an HTML page and based on user input, a source object is built and assigned to the audio object. They have controls, it plays, all is fine. I'd like them to be able to pick another file, build that new source element and have it replace the current one. However I can't seem to figure out how to kill/delete/unload the active one.
I can certainly pause the current, and replace that source element with my new one, but that doesn't do the trick. Do I need to destroy the audio element and then build a new one? Here's some snippet (assume there is always a source element when this is called to load a new source, I've verified mp3 etc.):
var aElems = document.getElementsByTagName("audio");
var source = document.createElement('source');
source.type= 'audio/mpeg';
source.src= 'podcast-'+pnpad+'.mp3';
aElems[0].pause();
var sElems = aElems[0].getElementsByTagName('source');
aElems[0].replaceChild(source, sElems[0]);
alert(aElems[0].innerHTML); // shows only the new child as expected
Thanks for any input.
Aucun commentaire:
Enregistrer un commentaire