From 338d7d3c87f35230f4fa7efe19da7b0ae56a152b Mon Sep 17 00:00:00 2001
From: croire <1432593898@qq.com>
Date: Sun, 16 Oct 2022 00:20:10 +0800
Subject: [PATCH] =?UTF-8?q?=E9=9F=B3=E8=A7=86=E9=A2=91=E5=88=86=E7=A6=BB?=
=?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=E9=80=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
DownKyi/Utils/DialogUtils.cs | 16 +++++
.../Toolbox/ViewExtractMediaViewModel.cs | 61 +++++++++++++------
DownKyi/Views/Toolbox/ViewExtractMedia.xaml | 6 +-
3 files changed, 60 insertions(+), 23 deletions(-)
diff --git a/DownKyi/Utils/DialogUtils.cs b/DownKyi/Utils/DialogUtils.cs
index 41b08d7..9852eb4 100644
--- a/DownKyi/Utils/DialogUtils.cs
+++ b/DownKyi/Utils/DialogUtils.cs
@@ -37,5 +37,21 @@ namespace DownKyi.Utils
return showDialog == true ? dialog.FileName : "";
}
+
+ ///
+ /// 选择多个视频dialog
+ ///
+ ///
+ public static string[] SelectMultiVideoFile()
+ {
+ // 选择文件
+ var dialog = new Microsoft.Win32.OpenFileDialog
+ {
+ Filter = "mp4 (*.mp4)|*.mp4",
+ Multiselect = true
+ };
+ var showDialog = dialog.ShowDialog();
+ return showDialog == true ? dialog.FileNames : new string[0];
+ }
}
}
diff --git a/DownKyi/ViewModels/Toolbox/ViewExtractMediaViewModel.cs b/DownKyi/ViewModels/Toolbox/ViewExtractMediaViewModel.cs
index bd8e1e7..cbd4cd6 100644
--- a/DownKyi/ViewModels/Toolbox/ViewExtractMediaViewModel.cs
+++ b/DownKyi/ViewModels/Toolbox/ViewExtractMediaViewModel.cs
@@ -18,11 +18,25 @@ namespace DownKyi.ViewModels.Toolbox
#region 页面属性申明
- private string videoPath;
- public string VideoPath
+ private string videoPathsStr;
+ public string VideoPathsStr
{
- get { return videoPath; }
- set { SetProperty(ref videoPath, value); }
+ get => videoPathsStr;
+ set
+ {
+ SetProperty(ref videoPathsStr, value);
+ }
+ }
+
+ private string[] videoPaths;
+ public string[] VideoPaths
+ {
+ get => videoPaths;
+ set
+ {
+ videoPaths = value;
+ VideoPathsStr = string.Join(Environment.NewLine, value);
+ }
}
private string status;
@@ -38,7 +52,7 @@ namespace DownKyi.ViewModels.Toolbox
{
#region 属性初始化
- VideoPath = string.Empty;
+ VideoPaths = new string[0];
#endregion
}
@@ -60,7 +74,7 @@ namespace DownKyi.ViewModels.Toolbox
return;
}
- VideoPath = DialogUtils.SelectVideoFile();
+ VideoPaths = DialogUtils.SelectMultiVideoFile();
}
// 提取音频事件
@@ -78,24 +92,27 @@ namespace DownKyi.ViewModels.Toolbox
return;
}
- if (VideoPath == "")
+ if (VideoPaths.Length <= 0)
{
eventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipNoSeletedVideo"));
return;
}
- // 音频文件名
- string audioFileName = VideoPath.Remove(VideoPath.Length - 4, 4) + ".aac";
Status = string.Empty;
await Task.Run(() =>
{
- // 执行提取音频程序
isExtracting = true;
- FFmpegHelper.ExtractAudio(VideoPath, audioFileName, new Action((output) =>
+ foreach (var item in VideoPaths)
{
- Status += output + "\n";
- }));
+ // 音频文件名
+ string audioFileName = item.Remove(item.Length - 4, 4) + ".aac";
+ // 执行提取音频程序
+ FFmpegHelper.ExtractAudio(item, audioFileName, new Action((output) =>
+ {
+ Status += output + "\n";
+ }));
+ }
isExtracting = false;
});
}
@@ -115,30 +132,34 @@ namespace DownKyi.ViewModels.Toolbox
return;
}
- if (VideoPath == "")
+ if (VideoPaths.Length <= 0)
{
eventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipNoSeletedVideo"));
return;
}
- // 视频文件名
- string videoFileName = VideoPath.Remove(VideoPath.Length - 4, 4) + "_onlyVideo.mp4";
Status = string.Empty;
await Task.Run(() =>
{
- // 执行提取视频程序
isExtracting = true;
- FFmpegHelper.ExtractVideo(VideoPath, videoFileName, new Action((output) =>
+ foreach (var item in VideoPaths)
{
- Status += output + "\n";
- }));
+ // 视频文件名
+ string videoFileName = item.Remove(item.Length - 4, 4) + "_onlyVideo.mp4";
+ // 执行提取视频程序
+ FFmpegHelper.ExtractVideo(item, videoFileName, new Action((output) =>
+ {
+ Status += output + "\n";
+ }));
+ }
isExtracting = false;
});
}
// Status改变事件
private DelegateCommand