Let's try the free bread, at least for the moment.
QQ music is believed to have been used more or less, and there are many music resources in it.
At this time, you may understand. That's right. We need to use QQ music Resources in the game as background music ~~~~~ Oh, yeah ~!
Ke, but since the QQ music online interface is encrypted, we need a series of work to decrypt and call it. Be prepared!
First put a preview:
The process is actually very simple.
Step 1: apply for access to the QQ music server.
Step 2: obtain different music lists (obtained based on your selection ). <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + tdrI/bK9o7q4 + b7dsrvNrMHQse29 + fingerprint/b7doaM8L3A + fingerprint + PGJyPgo8L3A + fingerprint = "brush: java;">/* QQ music plug-in */void function (w) {// QQ music object var QQMusic ={}; setInterval (function getJurisdiction (){///
Apply for access to the QQ music ServerInjectScript ("http://qzone-music.qq.com/fcg-bin/fcg_set_musiccookie.fcg? Fromtag = 31 "); return getJurisdiction;} (), 3x60*1000); function injectScript (url ){/// Reference script/// AddressVar oScript = document. createElement ("script"); oScript. src = url; oScript. charset = 'gb2312'; document. body. appendChild (oScript); document. body. removeChild (oScript);} function getAlbumPicture (albumId ){/// Obtain album Images/// Album No./// Album image address Return "http://imgcache.qq.com/music/photo/album/" + parseInt (albumId) % 100 + "/albumpic _" + albumId + "_0.jpg";} function getSingerPicture (singerId ){/// Get artist pictures/// Artist ID/// Artist image address Return "http://imgcache.qq.com/music/photo/singer/" + parseInt (singerId) % 100 + "/singerpic _" + singerId + "_0.jpg";} // callback function var cb = null; QQMusic. getGuessYouLike = function (callback ){/// Get the list you like/// Callback FunctionVar lableId = []; for (var I = 118; I <142; I ++) {lableId. push (I);} lableId. push (150,160); window. jsonCallBack = window. songRecCallback = listAnalysis; cb = callback; injectScript ("http://radio.cloud.music.qq.com/fcgi-bin/qm_guessyoulike.fcg? Labelid = "+ lableId [(lableId. length * Math. random () | 0] + "& start = 0 & num = 20 & rnd =" + new Date (). getTime () ;}; QQMusic. searchSongs = function (key, callback ){/// Search for songs/// Keywords/// Callback FunctionCb = callback; key = encodeURI (key); window. MusicJsonCallBack = searchAnalysis; injectScript ("http://s.plcloud.music.qq.com/fcgi-bin/smartbox.fcg? O_utf8 = 1 & utf8 = 1 & key = "+ key +" & inCharset = GB2312 & outCharset = UTF-8 ") ;}; QQMusic. getSongInfo = function (song, callback ){/// Obtain song Information/// Song object/// Callback FunctionCb = function (info) {info. name = song. name; info. singer = song. singer; info. imgUrl = getAlbumPicture (song. albumId); callback (info) ;}; window. jsonCallback = musicAnalysis; injectScript ("http://qzone-music.qq.com/fcg-bin/fcg_mv_getinfo_bysongid.fcg? Mids = "+ song. mid +" & uin = 10000 & loginUin = 0 & hostUin = 0 & outCharset = UTF-8 ") ;}; function listAnalysis (data ){/// Analysis of Random music list/// Random List DataVar playList = []; var regexp = new RegExp ('(upload | stream) (\ d + )\\. (music \\. qzone \\. soso \\. com | qqmusic \\. qq \\. com) \/(\ d + )\\. wma '); var replacement = function (word, x, a, y, B) {return 'stream' + (10 + Number ()) + '.qqmusic.qq.com/' + (18000000 + Number (B) + 'hangzhou';}; var songs = data. songs; for (var I = 0; I <songs. length; ++ I) {var song = songs [I]; var args = decodeURIComponent (song. data ). replace (/\ +/g ,''). split ('|'); var singerId = args [2]; var albumId = args [4]; var name = args [1]; var singer = args [3]; playList. push ({name: name, singer: singer, url: decodeURIComponent (song. url ). replace (regexp, replacement), imgUrl: getAlbumPicture (albumId), singerImgUrl: getSingerPicture (singerId)});} cb & cb (playList);}; function searchAnalysis (data) {///Search list resolution/// Search List DataVar songs = data. tips. song; var albums = data. tips. album; for (var I = songs. length; I --;) {songs [I] = {id: songs [I]. id, mid: songs [I]. mid, name: songs [I]. name, singer: songs [I]. singer_name, albumId: function () {for (var n = 0; n <albums. length; n ++) {if (albums [n]. singer_name = songs [I]. singer_name) {return albums [n]. id ;}}() };} cb & cb (songs) ;}; function musicAnalysis (data ){/// Single music analysis/// Single music source dataCb & cb ({url: 'http: // stream' + (10 + Number (data. num) + '.qqmusic.qq.com/' + (30000000 + Number (data. mvlist [0]. songid) + 'hangzhou'}) ;}; w. QQMusic = QQMusic;} (window );
OK !~ How can we get data and play it after writing it?
Good. Please refer to the following link ~
If we want to obtain the random song list, we only need to call
QQMusic.getGuessYouLike(function(list){ loadNewMusic(list[0]);});
Then ~ Let's write another loadNewMusic function to play it ~
Function loadNewMusic (musicInfo ){///Load new music///Music InformationVar audio = new Audio (); audio. autoplay = true; audio. src = musicInfo. url; audio. load ();}
OK!
RunRight !?