예제 #1
0
        /// <summary>
        /// 更换当前播放的音乐
        /// </summary>
        void ChangeCurrentSong()
        {
            PlayList    pl = null;
            PlayerState ps = GetPlayerState();

            while (_playListSongs.Count == 0)
            {
                pl = PlayList.GetPlayList(ps, "p");
                if (pl.Count == 0)
                {
                    TakeABreak();
                }
                else
                {
                    ChangePlayListSongs(pl);
                    break;
                }
            }
            lock (_playListSongs)
                Dispatcher.Invoke(new Action(() => { CurrentSong = _playListSongs.Dequeue(); }));
        }
예제 #2
0
        /// <summary>
        /// 获取播放列表
        /// </summary>
        /// <param name="playerState">播放器状态</param>
        /// <param name="operationType">操作类型</param>
        /// <returns>
        /// 播放列表
        /// </returns>
        internal static PlayList GetPlayList(Player.PlayerState playerState, string operationType)
        {
            //构造链接
            Parameters parameters = new Parameters();

            parameters["app_name"] = "radio";
            parameters["version"]  = "100";
            parameters["user_id"]  = playerState.CurrentUser.UserID;
            parameters["token"]    = playerState.CurrentUser.Token;
            parameters["expire"]   = playerState.CurrentUser.Expire;
            parameters["from"]     = "mainsite";
            parameters["context"]  = playerState.CurrentChannel.Context;
            parameters["sid"]      = playerState.CurrentSong != null ? playerState.CurrentSong.SongId : null;
            parameters["channel"]  = playerState.CurrentChannel.Id;
            parameters["type"]     = operationType;
            random.NextBytes(bytes);
            parameters["r"] = (BitConverter.ToUInt64(bytes, 0) % 0xFFFFFFFFFF).ToString("x10");

            if (playerState.CurrentUser.IsPro)
            {
                string kbps = null;
                switch (playerState.CurrentUser.ProRate)
                {
                case ProRate.Kbps64:
                    kbps = "64";
                    break;

                case ProRate.Kbps128:
                    kbps = "128";
                    break;

                case ProRate.Kbps192:
                    kbps = "192";
                    break;

                default:
                    break;
                }
                parameters["kbps"] = kbps;
            }

            string url = ConnectionBase.ConstructUrlWithParameters(ConfigurationManager.AppSettings["PlayList.BaseUrl"], parameters);

            //获取列表
            string json         = new ConnectionBase().Get(url, @"application/json, text/javascript, */*; q=0.01", @"http://douban.fm");
            var    jsonPlayList = Json.JsonHelper.FromJson <Json.PlayList>(json);

            if (jsonPlayList != null && jsonPlayList.r)
            {
                RaiseGetPlayListFailedEvent(json);
            }
            PlayList pl = new PlayList(jsonPlayList);

            //将小图更换为大图
            foreach (var s in pl)
            {
                s.Picture = s.Picture.Replace("/mpic/", "/lpic/").Replace("//otho.", "//img3.");
            }

            //去广告
            pl.RemoveAll(s => s.IsAd);

            return(pl);
        }
예제 #3
0
 void Report(string type, bool changeCurrentSong = true)
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
     {
         lock (workLock)
         {
             if (type == "s")
             {
                 _skipping = true;
             }
             if (type == "b")
             {
                 _neverring = true;
             }
             PlayList pl    = null;
             PlayerState ps = GetPlayerState();
             while (true)
             {
                 pl = PlayList.GetPlayList(ps, type);
                 if ((type == "p" || type == "n") && pl.Count == 0)
                 {
                     TakeABreak();
                 }
                 else if (type == "e")
                 {
                     break;
                 }
                 else if (ps.CurrentChannel.IsDj)
                 {
                     break;
                 }
                 else if (pl.Count == 0)
                 {
                     TakeABreak();
                 }
                 else
                 {
                     break;
                 }
             }
             PlayerState ps2 = GetPlayerState();
             if (ps.CurrentChannel == ps2.CurrentChannel)
             {
                 if (pl.Count > 0)
                 {
                     ChangePlayListSongs(pl);
                 }
                 if (changeCurrentSong)
                 {
                     ChangeCurrentSong();
                 }
             }
             if (type == "s")
             {
                 _skipping = false;
             }
             if (type == "b")
             {
                 _neverring = false;
             }
         }
     }));
 }