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 statusCommand; + public DelegateCommand StatusCommand => statusCommand ?? (statusCommand = new DelegateCommand(ExecuteStatusCommand)); /// diff --git a/DownKyi/Views/Toolbox/ViewExtractMedia.xaml b/DownKyi/Views/Toolbox/ViewExtractMedia.xaml index b47bb26..13675c6 100644 --- a/DownKyi/Views/Toolbox/ViewExtractMedia.xaml +++ b/DownKyi/Views/Toolbox/ViewExtractMedia.xaml @@ -9,7 +9,7 @@ - + @@ -28,11 +28,11 @@ + Text="{Binding VideoPathsStr, Mode=TwoWay}" />