Demo address: http://bejson.com/demos/qqmusic/
Code download: http://www.jqdemo.com/932.html
It was a long time ago to query QQ Music Just an interface comes out.
jQuery and jPlayer are used here to implement QQ space music query.
First of all, thank you bejson for collecting various useful interfaces, including of course the QQ space music interface.
Its URL is: http://www.bejson.com/webInterface.php
The interface we want to use is located in the music interface column on the bejson interface page.
QQ music interface address:
http://qzone-music.qq.com/fcg-bin/fcg_music_fav_getinfo.fcg?dirinfo=0&dirid=1&uin=QQ号&p=0.519638272547262&g_tk=1284234856
Give here Export the core code:
1. How to obtain the gtk parameters
function getGTK() {
var str = "@HR3etVm80";
var hash = 5381;
for (var i = 0,
len = str.length; i < len; i) {
hash = (hash << 5) str.charAt(i).charCodeAt();
}
var gtk = hash & 0x7fffffff;
//document.getElementById( "gtk").value = gtk;
return gtk;
}
2. Request QQ space interface
function getMusicId() {
var qqNo = document.getElementById("qqNo").value;
var url = 'http://qzone-music.qq.com/fcg-bin/cgi_playlist_xml.fcg?uin=' qqNo '&json=1&g_tk=' getGTK();
$.getScript(url);
}
3. Callback to assemble JSON
According to the returned JSON interface
We parse the music JSON
function jsonCallback(data) {
if(data.code==1){
alert(data.msg );
return;
}
var songs = data.qqmusic.playlist.song;
var dataStr = "[";
for (var i = 0; i < songs. length; i ) {
dataStr = "{";
dataStr = "title:'" songs[i].xsong_name "',";
dataStr = "mp3:'" songs[i]. xsong_url "'";
dataStr = "}";
if (i < songs.length) {
dataStr = ',';
}
}
dataStr = ' ]';
eval("ds=" dataStr);
newPlayer(ds);
}
Finally we call the jPlay player:
var playList;
function newPlayer(data) {
playList = new jPlayerPlaylist ({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
},
data, {
swfPath: "js",
supplied: "mp3",
wmode: "window"
});
}