JQuery + JSON + jPlayer example of QQ space music query function _ jquery

Source: Internet
Author: User
Tags gtk
This article introduces jQuery + JSON + jPlayer to implement music query in the QQ space. If you are interested in the specific implementation process, I hope it will be helpful to you.
Demo address: http://bejson.com/demos/qqmusic/
Code download: http://www.jqdemo.com/932.html
Querying QQ music is an interface that came out a long time ago.
Here, jQuery and jPlayer are used to query QQ space music.
First of all, I would like to thank bejson for its various useful interfaces, including the QQ space music interfaces.
Its URL is: http://www.bejson.com/webInterface.php
The interface we want to use is located in the music interface bar 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 No. & p = 0.519638272547262 & g_tk = 1284234856
The core code is provided here:
1. How to obtain the gtk Parameter

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 the QQ space Interface

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 Assembly JSON
Based on the returned JSON Interface

Let's parse the music JSON

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:

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"
});
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.