| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2079 人关注过本帖
标题:如何获取音乐API中的MP3真实地址
只看楼主 加入收藏
luoqingwen
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-12-3
收藏
 问题点数:0 回复次数:0 
如何获取音乐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
});
搜索更多相关主题的帖子: 百度音乐 function MP3地址 widget title 
2016-12-21 16:15
快速回复:如何获取音乐API中的MP3真实地址
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015847 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved