コード例 #1
0
 internal static void Init()
 {
     new Thread(() =>
     {
         while (true)
         {
             try
             {
                 Thread.Sleep(1000);
                 if (running && time != zero)
                 {
                     if ((DateTime.Now - time) >= new TimeSpan(0, 0, second))
                     {
                         Center.Logg("下载速度长时间过慢,自动切断下载", true, true);
                         DownloadControl.CancelDownload();
                     }
                 }
             }
             catch (Exception) { }
         }
     })
     {
         Name = "DownloadWatchDog", IsBackground = true
     }.Start();
 }
コード例 #2
0
        /// <summary>
        /// 删除歌曲事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            var menuItem    = (MenuItem)sender;
            var contextMenu = (ContextMenu)menuItem.Parent;
            var items       = (DataGrid)contextMenu.PlacementTarget;

            if (items.SelectedCells.Count == 0)
            {
                return;
            }
            var item = items.SelectedCells[0].Item as SongItem;

            if (item == null)
            {
                return;
            }
            switch (item.Status)
            {
            case SongItem.SongStatus.WaitingDownload:
                Center.RemoveSong(item);
                return;

            case SongItem.SongStatus.Downloading:
                DownloadControl.CancelDownload();
                return;

            default:
            case SongItem.SongStatus.WaitingPlay:
                if (item.FilePath != null && item.FilePath != "")
                {
                    new System.Threading.Thread((object o) => { try { System.IO.File.Delete(o.ToString()); } catch (Exception) { } })
                    {
                        IsBackground = true, Name = "切歌后删除文件"
                    }
                }
                .Start(item.FilePath);
                Center.RemoveSong(item);
                return;
コード例 #3
0
        internal static void DGJ_AdminComment(string msg)
        {
            if (string.IsNullOrWhiteSpace(msg) || !Config.DanmakuControl)
            {
                return;
            }           // 如果弹幕msg没有内容或者不允许弹幕控制

            string[] msgs = msg.Split(new string[] { " " }, System.StringSplitOptions.RemoveEmptyEntries);
            switch (msgs[0])
            {
            case "暫停":
            case "暂停":
                if (PlayControl.Pause())
                {
                    Log("歌曲已经暂停");
                }
                return;

            case "播放":
                if (PlayControl.Play())
                {
                    Log("歌曲继续播放");
                }
                return;

            case "切歌":
                if (PlayControl.Next())
                {
                    Log("已经切掉正在播放的歌曲");
                }
                return;

            case "刪歌":
            case "删歌":
                int num;
                if (msgs.Length >= 2 && int.TryParse(msgs[1], out num))
                {
                    num--;
                    if (num >= 0 && num < Center.Songs.Count)
                    {
                        SongItem item = Center.Songs[num];
                        Log($"切掉了 {item.User} 点的 {item.SongName}", true);
                        switch (item.Status)
                        {
                        case SongItem.SongStatus.WaitingDownload:
                            Center.RemoveSong(item);
                            return;

                        case SongItem.SongStatus.Downloading:
                            DownloadControl.CancelDownload();
                            return;

                        default:
                        case SongItem.SongStatus.WaitingPlay:
                            if (item.FilePath != null && item.FilePath != "")
                            {
                                new Thread((object o) =>
                                {
                                    try
                                    {
                                        File.Delete(o.ToString());
                                    }
                                    catch (Exception) { }
                                })
                                {
                                    IsBackground = true,
                                    Name         = "切歌后删除文件"
                                }
                            }
                            .Start(item.FilePath);
                            Center.RemoveSong(item);
                            return;

                        case SongItem.SongStatus.Playing:
                            PlayControl.Next();
                            return;
                        }
                    }