Home > Web Front-end > JS Tutorial > jQuery+JSON+jPlayer implements QQ space music query

jQuery+JSON+jPlayer implements QQ space music query

伊谢尔伦
Release: 2016-11-22 13:27:39
Original
1668 people have browsed it

Querying QQ Music is an interface that came out a long time ago.

jQuery and jPlayer are used here to implement QQ space music query.

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

given here core code :

1. How to obtain gtk parameters

f

unction 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;
}
Copy after login

2. Request QQ space interface

function getMusicId() {
var qqNo = document.getElementById("qqNo").value;
var url = &#39;http://qzone-music.qq.com/fcg-bin/cgi_playlist_xml.fcg?uin=&#39; + qqNo + &#39;&json=1&g_tk=&#39; + getGTK();
$.getScript(url);
}
Copy after login

3. Callback to assemble JSON

According to the returned JSON interface

jQuery+JSON+jPlayer implements QQ space music query

Let’s 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:&#39;" + songs[i].xsong_name + "&#39;,";
    dataStr += "mp3:&#39;" + songs[i].xsong_url + "&#39;";
    dataStr += "}";
    if (i < songs.length) {
      dataStr += &#39;,&#39;;
    }
  }
  dataStr += &#39;]&#39;;
  eval("ds=" + dataStr);
  newPlayer(ds);
}
Copy after login

Finally we call 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"
  });
}
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template