コード例 #1
0
        private static void onDownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            bool sucFlag = true;

            if (e.Cancelled)
            {
                Center.Logg("下载被取消");
                Center.Mainw.setDownloadStatus("下载被取消");
                sucFlag = false;
                try
                { File.Delete(dlItem.FilePath); }
                catch (Exception) { }
            }
            else if (e.Error != null)
            {
                Center.Logg("下载出错 " + e.Error.Message, true, true);
                Center.Mainw.setDownloadStatus("下载出错 " + e.Error.Message);
                sucFlag = false;
            }

            if (sucFlag)
            {
                Center.Logg("歌曲下载 下载成功:" + dlItem._SongName, false, true);
                Center.Mainw.setDownloadStatus("下载完毕");
                dlItem.setStatus(SongItem.SongStatus.WaitingPlay);
            }
            else
            {
                Center.RemoveSong(dlItem);
            }
            DownloadWatchDog.Stop();
            wc           = null;
            downloadFlag = false; // 允许进行下一首歌的下载
        }
コード例 #2
0
        private static void Download(SongItem item)
        {
            try
            { Directory.CreateDirectory(Config.SongsCachePath); }
            catch (Exception) { }

            dlItem = item;
            dlItem.setStatus(SongItem.SongStatus.Downloading);

            if (item.Module.HandleDownlaod) // 如果搜索模块负责下载文件
            {
                Center.Mainw.setDownloadStatus("由搜索模块负责下载中");
                switch (item.Module.SafeDownload(item))
                {
                case 1:     // 下载成功
                    dlItem.setStatus(SongItem.SongStatus.WaitingPlay);
                    Center.Logg("歌曲下载 下载成功:" + item._SongName);
                    Center.Mainw.setDownloadStatus("搜索模块返回下载成功");
                    return;

                case 0:     // 下载失败 错误信息由module输出
                default:
                    Center.RemoveSong(item);
                    Center.Mainw.setDownloadStatus("搜索模块返回下载失败");
                    return;
                }
            }
            else // 如果搜索模块不负责下载文件
            {
                wc = new WebClient();

                wc.DownloadProgressChanged += onDownloadProgressChanged;
                wc.DownloadFileCompleted   += onDownloadFileCompleted;
                wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.450 Safari/537.35");
                try
                {
                    sw.Reset();
                    lastUpdateDownloadedSize = 0;
                    lastUpdateTime           = DateTime.Now;
                    wc.DownloadFileAsync(new Uri(item._DownloadURL), item._FilePath);
                    Center.Mainw.setDownloadStatus("正在连接服务器");
                    sw.Start();
                    DownloadWatchDog.Start();
                    downloadFlag = true; // 正在下载歌曲
                }
                catch (Exception ex)
                {
                    sw.Reset();
                    Center.Logg("下载歌曲" + item._SongName + "出错:" + ex.Message, true, true);
                    Center.Mainw.setDownloadStatus("下载失败:" + ex.Message);
                }

                while (downloadFlag)
                {
                    Thread.Sleep(500);
                }
                dlItem = null;
            }
        }
コード例 #3
0
ファイル: PlayControl.cs プロジェクト: hxdnshx/DMPlugin_DGJ
        /// <summary>
        /// 从文件和播放列表里移除歌曲
        /// </summary>
        /// <param name="song"></param>
        private static void RemoveSong(SongItem song)
        {
            try
            {
                File.Delete(song._FilePath);
            }
            catch (System.Exception ex)
            {
                Center.Logg("播放模块 删除歌曲缓存失败:" + ex.Message);
            }

            Center.RemoveSong(song);
        }
コード例 #4
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;
コード例 #5
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;
                        }
                    }