Home  >  Article  >  Web Front-end  >  jQuery JSON jPlayer implements QQ space music query function example_jquery

jQuery JSON jPlayer implements QQ space music query function example_jquery

WBOY
WBOYOriginal
2016-05-16 17:32:051126browse
jQuery JSON jPlayer implements QQ space music query function example_jquery
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
Copy the code The code is as follows:

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
Copy Code The code is as follows:

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
jQuery JSON jPlayer implements QQ space music query function example_jquery
We parse the music JSON
Copy the code The code is as follows:

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:
Copy code The code is as follows:

var playList;
function newPlayer(data) {
playList = new jPlayerPlaylist ({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
},
data, {
swfPath: "js",
supplied: "mp3",
wmode: "window"
});
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn