//合并视频 private void toolCombineVideo_Click(object sender, EventArgs e) { if (!VideoCombineHelper.CheckFileExists()) { var result = MessageBox.Show("尚未安装视频合并所需要的插件,是否立即下载?", "视频合并插件", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == System.Windows.Forms.DialogResult.Yes) { FormNew.ShowForm("视频合并插件"); } return; } ListViewItem item = lsv.SelectedItems[0]; TaskInfo task = GetTask(new Guid((string)item.Tag)); new Thread(new ThreadStart(() => { var arr = task.Settings["VideoCombine"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length >= 3) { task.Settings["VideoCombineInProgress"] = "true"; string output = arr[arr.Length - 1]; Array.Resize<string>(ref arr, arr.Length - 1); var helper = new VideoCombineHelper(); helper.Combine(arr, output, (o) => { this.Invoke(new Action<int>((progress) => { item.SubItems[GetColumn("Name")].Text = "正在合并: " + progress.ToString() + "%"; }), o); }); task.Settings.Remove("VideoCombineInProgress"); } //更新UI this.Invoke(new MethodInvoker(() => { item.SubItems[GetColumn("Name")].Text = task.Title; })); })).Start(); lsv.SelectedIndices.Clear(); }
}//end TipText /// <summary> /// 下载完成(需要判断下载完成还是用户手动停止) /// </summary> public void Finish(object e) { //非UI线程中执行 ParaFinish p = (ParaFinish)e; TaskInfo task = p.SourceTask; ListViewItem item = (ListViewItem)task.UIItem; //如果下载成功 if (p.Successed) { this.Invoke(new MethodInvoker(() => { item.SubItems[GetColumn("Status")].Text = task.Status.ToString(); item.SubItems[GetColumn("Progress")].Text = @"100.00%"; //下载进度 item.SubItems[GetColumn("Speed")].Text = ""; //下载速度 })); //视频合并 - if (!Tools.IsRunningOnMono && chkAutoCombine.Checked && task.Settings.ContainsKey("VideoCombine")) { var arr = task.Settings["VideoCombine"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length >= 3) { task.Settings["VideoCombineInProgress"] = "true"; string output = arr[arr.Length - 1]; Array.Resize<string>(ref arr, arr.Length - 1); var helper = new VideoCombineHelper(); helper.Combine(arr, output, (o) => { this.Invoke(new Action<int>((progress) => { item.SubItems[GetColumn("Name")].Text = "正在合并: " + progress.ToString() + "%"; }), o); }); task.Settings.Remove("VideoCombineInProgress"); } } //更新UI this.Invoke(new MethodInvoker(() => { item.SubItems[GetColumn("Name")].Text = task.Title; })); //打开文件夹 if (CoreManager.ConfigManager.Settings.OpenFolderAfterComplete && !Tools.IsRunningOnMono) Process.Start(CoreManager.ConfigManager.Settings.SavePath); //播放声音 if (CoreManager.ConfigManager.Settings.PlaySound) { try { System.Media.SoundPlayer player = new System.Media.SoundPlayer(); //优先播放设置文件中的声音(必须是wav格式&忽略大小写) if (File.Exists(CoreManager.ConfigManager.Settings.SoundFile) && CoreManager.ConfigManager.Settings.SoundFile.EndsWith(".wav", StringComparison.CurrentCultureIgnoreCase)) { player.SoundLocation = CoreManager.ConfigManager.Settings.SoundFile; } else { //然后播放程序目录下的msg.wav文件 if (File.Exists(Path.Combine(Application.StartupPath, "msg.wav"))) { player.SoundLocation = Path.Combine(Application.StartupPath, "msg.wav"); } else //如果都没有则播放资源文件中的声音文件 { player.Stream = Resources.remind; } } player.Load(); player.Play(); player.Dispose(); } catch { } } } else //如果用户取消下载 { if (item != null) { //更新item this.Invoke(new MethodInvoker(() => { item.SubItems[GetColumn("Status")].Text = task.Status.ToString(); item.SubItems[GetColumn("Speed")].Text = ""; //下载速度 })); } } //移除item this.Invoke(new MethodInvoker(() => { if (lsv.Items.Contains(item)) if (!IsMatchCurrentFilter(task)) lsv.Items.Remove(item); })); }