Created
November 16, 2010 14:58
-
-
Save longseespace/701898 to your computer and use it in GitHub Desktop.
Zing Audio Player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var baseurl = 'http://mp3.zing.vn'; | |
var token = 'fb01753add840692df1029d5508a8ee6'; | |
var params = document.querySelectorAll('param[value*="mp3.zing.vn"]'); | |
if (params.length > 0) { | |
for (var i=0; i < params.length; i++) | |
{ | |
var zingPlaylist = new Array(); | |
var object = params[i].parentNode; | |
var xmlurl = baseurl + object.querySelector('param[name=flashvars]').value.replace('xmlURL=', ''); | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.open("GET", xmlurl, true); | |
xmlhttp.onreadystatechange=function() { | |
if (xmlhttp.readyState == 4) { | |
sources = xmlhttp.responseXML.querySelectorAll('source'); | |
for (var j=0; j < sources.length; j++) { | |
zingPlaylist.push(sources[j].textContent + '?q=' + token + '&t'); | |
}; | |
} | |
if (zingPlaylist.length > 0) { | |
var songID = parseInt(xmlurl.replace(/.*songID=(.+?)&.*/, '$1'), 10); | |
object.innerHTML = audioHTML(zingPlaylist[songID]); | |
var theAudioPlayer = object.children[0]; | |
theAudioPlayer.autoplay = true; | |
theAudioPlayer.load(); | |
theAudioPlayer.play(); | |
if (zingPlaylist.length == 1) { | |
theAudioPlayer.loop = true; | |
} else { | |
theAudioPlayer.addEventListener('ended', function(){ | |
if (++songID <= zingPlaylist.length) { | |
this.src = zingPlaylist[songID]; | |
this.load(); | |
this.play(); | |
}; | |
}); | |
} | |
} else { | |
object.innerHTML = 'Songs could not be loaded. Please refresh your browser and try again.'; | |
} | |
} | |
xmlhttp.send(null) | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment