私はそれが良い答えですので、私は投票したマイク!ここで私は彼が提案したことをどのようにしたのかの例です。
http://jsfiddle.net/earlonrails/tTF89/6/
HTML
<audio controls="controls" width="300px" id="audioPlayer">
<!-- load broken audio -->
<source type="audio/mpeg" src="http://www.google.com/4/0/4" />
</audio>
javascriptの
var urlOne = 'http://www.tonycuffe.com/mp3/tail%20toddle.mp3',
urlTwo = 'http://freeplaymusic.com/search/download_file.php?id=4&dur=0&type=mp3';
function attrs(element, attributes) {
for (var prop in attributes) {
element.setAttribute(prop, attributes[prop]);
}
}
function reloadAudioTag(path, player, holder) {
if (player) player.parentNode.removeChild(player);
var player = document.createElement('audio'),
source = document.createElement('source');
source.type = "audio/mpeg"
attrs(player, {
"width": "300px",
"controls": "controls",
"autoplay": "autoplay",
"id": 'audioPlayer'
});
player.appendChild(source);
if (holder) {
holder.insertBefore(player, holder.childNodes[0]);
} else {
document.body.appendChild(player);
}
source.src = path;
player.load();
return player;
}
console.log("called!");
reloadAudioTag(urlOne, document.getElementById("audioPlayer"));
console.log("Still going!");
setTimeout(function() {
reloadAudioTag(urlTwo, document.getElementById("audioPlayer"));
console.log("Finished!");
}, 5000);