如何获取音乐API中的MP3真实地址
以下代码节选百度音乐前端团队开发的音乐API接口及解析,不解的是解析出的MP3地址存放于哪个变量中,请达人点解,谢谢!__d("widget.musicbox.musicbox", ["common.js.jquery-ui", "widget.musicbox.marquee", "common.js.format"],
function(g, h, e, d) {
d("common.js.jquery-ui");
d("widget.musicbox.marquee");
var c = d("common.js.format");
$.widget("hao123.musicbox", {
options: {
tpl: "<div class='title'><a class='name' href='http://music.baidu.com/song/#{songid}'>#{name}</a><span class='split'>-</span><a class='author' href='http://music.baidu.com/artist/#{uid}'>#{author}</a></div>",
hotUrl: "http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.billboard.billList&type=2&from=ext&client=qingwen",
playUrl: "http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.play&from=ext&client=qingwen",
playerUrl: "muPlayer/dist/player.min.js",
baseDir: "http://mu7.,
mp3Url: "http://play.baidu.com/?__m=mboxCtrl.playSong&__a=#{id}&__o=||hao123_player",
playingCls: "playing",
volMidCls: "vol-mid",
volLargeCls: "vol-large",
volMuteCls: "vol-mute"
},
_init: function() {
var a = this;
this._initPlayer(function() {
a._getPlayList(function() {
a._initVolume();
a._bindEvent()
})
})
},
_initPlayer: function(a) {
var b = this,
c = b.options;
$.getScript(c.playerUrl,
function() {
_mu.Player.prototype._fetch = function() {
var a, c = this,
i = this.getCur();
a = $.Deferred();
this.getUrl() === i ? a.resolve() : b._getUrlByID(i,
function(b) {
c.setUrl(b);
a.resolve()
});
this.trigger("player:fetchend", i);
return a.promise()
};
b.player = new _mu.Player({
baseDir: c.baseDir,
absoluteUrl: !1,
volume: b.volume
});
a && a()
})
},
_getPlayList: function(a) {
var b = this,
i = b.options;
b._cachedJsonp(i.hotUrl, "mp3_hotlist",
function(f) {
var d, e, g;
if (22E3 == f.error_code) {
for (var f = f.song_list,
h = 0,
j = f.length; h < j; h++) d = f[h],
e = d.song_id,
g = {},
g.name = d.title,
g.author = d.author,
g.uid = d.ting_uid,
b.playList[e] = g,
b.player.add(e);
0 < j && (f = f[Math.random() * j | 0].song_id, b.player.setCur(f), b._renderInfo(f), b.$open.attr("href", c(i.mp3Url, {
id: f
})));
a && a()
}
})
},
_getUrlByID: function(a, b) {
this._cachedJsonp(this.options.playUrl + "&songid=" + a, "mp3_play_" + a,
//this._cachedJsonp(this.options.playUrl, "mp3_play_" + a,
function(a) {
22E3 == a.error_code && (a = a.bitrate.file_link, b && b(a))
})
},
_cachedJsonp: function(a, b, c) {
var d = window[b];
window[b] = function(a) {
c && c(a)
};
alert(a);
$.ajax({
dataType:"script",
url: a + ("&callback=" + b),
cache: !0,
error:function(){
},
success:function(){
window[b] = d;
if (void 0 === d) try {
delete window[b]
} catch(a) {}
}
})
}
});
return e
});