From 62789fa03665f2c7da7762a1f2cd5c2fd04bb6be Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Wed, 10 Mar 2021 13:28:39 +0100 Subject: [PATCH] Implementation for the mpv title property. mpv window-scale property works now exactly like in mpv. --- Changelog.md | 7 +++ Release.ps1 | 2 + mpv.net/Misc/App.cs | 5 -- mpv.net/Misc/Commands.cs | 59 ++++++++++++---------- mpv.net/Misc/Help.cs | 66 +++++++++++++++++++++++-- mpv.net/Misc/Misc.cs | 13 +++-- mpv.net/Misc/NewLine.cs | 8 --- mpv.net/Misc/PowerShell.cs | 2 +- mpv.net/Misc/Program.cs | 6 +-- mpv.net/Misc/RegistryHelp.cs | 64 ------------------------ mpv.net/Resources/input.conf.txt | 7 ++- mpv.net/WPF/EverythingWindow.xaml.cs | 2 +- mpv.net/WPF/SetupWindow.xaml.cs | 6 +-- mpv.net/WinForms/MainForm.cs | 74 +++++++++++++++++++++------- mpv.net/mpv.net.csproj | 2 - mpv.net/mpv/Core.cs | 32 ++++++++---- 16 files changed, 206 insertions(+), 149 deletions(-) delete mode 100644 mpv.net/Misc/NewLine.cs delete mode 100644 mpv.net/Misc/RegistryHelp.cs diff --git a/Changelog.md b/Changelog.md index 36fae53..0950c3c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,11 @@ +5.4.8.8 Beta (2021-03-??) +========================= + +- The mpv window-scale property works now exactly like in mpv. +- Implementation for the mpv title property. + + 5.4.8.7 Beta (2021-03-09) ========================= diff --git a/Release.ps1 b/Release.ps1 index c664794..173f3fe 100644 --- a/Release.ps1 +++ b/Release.ps1 @@ -10,6 +10,8 @@ $7z = 'C:\Program Files\7-Zip\7z.exe' $cloudDirectories = 'C:\Users\frank\OneDrive\Public\mpv.net\', 'C:\Users\frank\Dropbox\Public\mpv.net\' +cd $PSScriptRoot + function UploadBeta($sourceFile) { foreach ($cloudDirectory in $cloudDirectories) diff --git a/mpv.net/Misc/App.cs b/mpv.net/Misc/App.cs index 044670b..453b346 100644 --- a/mpv.net/Misc/App.cs +++ b/mpv.net/Misc/App.cs @@ -12,11 +12,6 @@ namespace mpvnet { public static class App { - public static string[] VideoTypes { get; set; } = "264 265 asf avc avi avs dav flv h264 h265 hevc m2t m2ts m2v m4v mkv mov mp4 mpeg mpg mpv mts ts vob vpy webm wmv y4m".Split(' '); - public static string[] AudioTypes { get; set; } = "mp3 mp2 ac3 ogg opus flac wav w64 m4a dts dtsma dtshr dtshd eac3 thd thd+ac3 mka aac mpa".Split(' '); - public static string[] ImageTypes { get; set; } = { "jpg", "bmp", "gif", "png" }; - public static string[] SubtitleTypes { get; } = { "srt", "ass", "idx", "sup", "ttxt", "ssa", "smi" }; - public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName; public static string ConfPath { get => core.ConfigFolder + "mpvnet.conf"; } public static string ProcessInstance { get; set; } = "single"; diff --git a/mpv.net/Misc/Commands.cs b/mpv.net/Misc/Commands.cs index 02de038..e86b84c 100644 --- a/mpv.net/Misc/Commands.cs +++ b/mpv.net/Misc/Commands.cs @@ -1,5 +1,6 @@  using System; +using System.Globalization; using System.IO; using System.Linq; using System.Threading; @@ -9,7 +10,7 @@ using System.Windows; using VB = Microsoft.VisualBasic; -using static NewLine; +using static mpvnet.NewLine; using static mpvnet.Core; namespace mpvnet @@ -20,36 +21,37 @@ namespace mpvnet { switch (id) { - case "open-files": OpenFiles(args); break; - case "update-check": UpdateCheck.CheckOnline(true); break; - case "open-url": OpenURL(); break; - case "open-optical-media": Open_DVD_Or_BD_Folder(); break; - case "manage-file-associations": // deprecated 2019 - case "show-setup-dialog": ShowDialog(typeof(SetupWindow)); break; + case "add-files-to-playlist": OpenFiles("append"); break; // deprecated 2019 case "cycle-audio": CycleAudio(); break; + case "execute-mpv-command": ExecuteMpvCommand(); break; case "load-audio": LoadAudio(); break; case "load-sub": LoadSubtitle(); break; - case "execute-mpv-command": ExecuteMpvCommand(); break; - case "show-history": ShowHistory(); break; - case "show-media-search": ShowDialog(typeof(EverythingWindow)); break; - case "show-command-palette": ShowDialog(typeof(CommandPaletteWindow)); break; - case "show-about": ShowDialog(typeof(AboutWindow)); break; - case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break; - case "show-input-editor": ShowDialog(typeof(InputWindow)); break; + case "manage-file-associations": // deprecated 2019 case "open-conf-folder": ProcessHelp.ShellExecute(core.ConfigFolder); break; - case "shell-execute": ProcessHelp.ShellExecute(args[0]); break; - case "show-info": ShowInfo(); break; + case "open-files": OpenFiles(args); break; + case "open-optical-media": Open_DVD_Or_BD_Folder(); break; + case "open-url": OpenURL(); break; case "playlist-first": PlaylistFirst(); break; case "playlist-last": PlaylistLast(); break; + case "scale-window": ScaleWindow(float.Parse(args[0], CultureInfo.InvariantCulture)); break; + case "shell-execute": ProcessHelp.ShellExecute(args[0]); break; + case "show-about": ShowDialog(typeof(AboutWindow)); break; + case "show-audio-devices": ShowTextWithEditor("audio-device-list", core.get_property_osd_string("audio-device-list")); break; + case "show-command-palette": ShowDialog(typeof(CommandPaletteWindow)); break; + case "show-commands": ShowCommands(); break; + case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break; + case "show-decoders": ShowTextWithEditor("decoder-list", mpvHelp.GetDecoders()); break; + case "show-demuxers": ShowTextWithEditor("demuxer-lavf-list", mpvHelp.GetDemuxers()); break; + case "show-history": ShowHistory(); break; + case "show-info": ShowInfo(); break; + case "show-input-editor": ShowDialog(typeof(InputWindow)); break; + case "show-keys": ShowTextWithEditor("input-key-list", core.get_property_string("input-key-list").Replace(",", BR)); break; + case "show-media-search": ShowDialog(typeof(EverythingWindow)); break; case "show-profiles": ShowTextWithEditor("profile-list", mpvHelp.GetProfiles()); break; case "show-properties": ShowProperties(); break; - case "show-commands": ShowCommands(); break; - case "show-keys": ShowTextWithEditor("input-key-list", core.get_property_string("input-key-list").Replace(",", BR)); break; - case "add-files-to-playlist": OpenFiles("append"); break; // deprecated 2019 - case "show-audio-devices": ShowTextWithEditor("audio-device-list", core.get_property_osd_string("audio-device-list")); break; - case "show-decoders": ShowTextWithEditor("decoder-list", mpvHelp.GetDecoders()); break; case "show-protocols": ShowTextWithEditor("protocol-list", mpvHelp.GetProtocols()); break; - case "show-demuxers": ShowTextWithEditor("demuxer-lavf-list", mpvHelp.GetDemuxers()); break; + case "show-setup-dialog": ShowDialog(typeof(SetupWindow)); break; + case "update-check": UpdateCheck.CheckOnline(true); break; default: Msg.ShowError($"No command '{id}' found."); break; } } @@ -159,7 +161,7 @@ namespace mpvnet { fileSize = new FileInfo(path).Length; - if (App.AudioTypes.Contains(path.Ext())) + if (Core.AudioTypes.Contains(path.Ext())) { using (MediaInfo mediaInfo = new MediaInfo(path)) { @@ -183,7 +185,7 @@ namespace mpvnet return; } } - else if (App.ImageTypes.Contains(path.Ext())) + else if (Core.ImageTypes.Contains(path.Ext())) { using (MediaInfo mediaInfo = new MediaInfo(path)) { @@ -243,7 +245,8 @@ namespace mpvnet InvokeOnMainThread(new Action(() => { string clipboard = System.Windows.Forms.Clipboard.GetText(); - if (string.IsNullOrEmpty(clipboard) || (!clipboard.Contains("://") && !File.Exists(clipboard)) || clipboard.Contains("\n")) + if (string.IsNullOrEmpty(clipboard) || (!clipboard.Contains("://") && !File.Exists(clipboard)) || + clipboard.Contains("\n")) { App.ShowError("No URL found", "The clipboard does not contain a valid URL or file."); return; @@ -339,9 +342,13 @@ namespace mpvnet static void ShowTextWithEditor(string name, string text) { string file = Path.GetTempPath() + $"\\{name}.txt"; - //UTF8 without BOM File.WriteAllText(file, BR + text.Trim() + BR); ProcessHelp.ShellExecute(file); } + + static void ScaleWindow(float factor) + { + core.RaiseScaleWindow(factor); + } } } diff --git a/mpv.net/Misc/Help.cs b/mpv.net/Misc/Help.cs index 943cf86..2de046b 100644 --- a/mpv.net/Misc/Help.cs +++ b/mpv.net/Misc/Help.cs @@ -5,8 +5,10 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; +using Microsoft.Win32; + using static mpvnet.Core; -using static NewLine; +using static mpvnet.NewLine; namespace mpvnet { @@ -18,7 +20,6 @@ namespace mpvnet { proc.StartInfo.FileName = file; proc.StartInfo.Arguments = arguments; - // default is true in .NET Framework and false in .NET Core proc.StartInfo.UseShellExecute = false; proc.Start(); } @@ -30,7 +31,6 @@ namespace mpvnet { proc.StartInfo.FileName = file; proc.StartInfo.Arguments = arguments; - // default is true in .NET Framework and false in .NET Core proc.StartInfo.UseShellExecute = true; proc.Start(); } @@ -187,4 +187,64 @@ namespace mpvnet return string.Join(BR, list.Split(',').OrderBy(a => a)); } } + + public class RegistryHelp + { + public static string ApplicationKey { get; } = @"HKCU\Software\" + Application.ProductName; + + public static void SetValue(string path, string name, object value) + { + using (RegistryKey regKey = GetRootKey(path).CreateSubKey(path.Substring(5), RegistryKeyPermissionCheck.ReadWriteSubTree)) + regKey.SetValue(name, value); + } + + public static string GetString(string path, string name, string defaultValue = "") + { + object value = GetValue(path, name, defaultValue); + return !(value is string) ? defaultValue : value.ToString(); + } + + public static int GetInt(string path, string name, int defaultValue = 0) + { + object value = GetValue(path, name, defaultValue); + return !(value is int) ? defaultValue : (int)value; + } + + public static object GetValue(string path, string name, object defaultValue = null) + { + using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5))) + return regKey == null ? null : regKey.GetValue(name, defaultValue); + } + + public static void RemoveKey(string path) + { + try + { + GetRootKey(path).DeleteSubKeyTree(path.Substring(5), false); + } + catch { } + } + + public static void RemoveValue(string path, string name) + { + try + { + using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5), true)) + if (regKey != null) + regKey.DeleteValue(name, false); + } + catch { } + } + + static RegistryKey GetRootKey(string path) + { + switch (path.Substring(0, 4)) + { + case "HKLM": return Registry.LocalMachine; + case "HKCU": return Registry.CurrentUser; + case "HKCR": return Registry.ClassesRoot; + default: throw new Exception(); + } + } + } } diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index 4d39905..66ced47 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -1,4 +1,5 @@  +using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -16,6 +17,12 @@ using static mpvnet.Core; namespace mpvnet { + public static class NewLine + { + public static string BR = Environment.NewLine; + public static string BR2 = Environment.NewLine + Environment.NewLine; + } + public class Sys { public static bool IsDarkTheme { @@ -67,13 +74,13 @@ namespace mpvnet RegistryHelp.SetValue($@"HKCR\" + "." + ext, null, ExeFilenameNoExt + "." + ext); RegistryHelp.SetValue($@"HKCR\" + "." + ext + @"\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, ""); - if (App.VideoTypes.Contains(ext)) + if (Core.VideoTypes.Contains(ext)) RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "video"); - if (App.AudioTypes.Contains(ext)) + if (Core.AudioTypes.Contains(ext)) RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "audio"); - if (App.ImageTypes.Contains(ext)) + if (Core.ImageTypes.Contains(ext)) RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "image"); RegistryHelp.SetValue($@"HKCR\" + ExeFilenameNoExt + "." + ext + @"\shell\open\command", null, $"\"{ExePath}\" \"%1\""); diff --git a/mpv.net/Misc/NewLine.cs b/mpv.net/Misc/NewLine.cs deleted file mode 100644 index 3d56f17..0000000 --- a/mpv.net/Misc/NewLine.cs +++ /dev/null @@ -1,8 +0,0 @@ - -using System; - -public static class NewLine -{ - public static string BR = Environment.NewLine; - public static string BR2 = Environment.NewLine + Environment.NewLine; -} diff --git a/mpv.net/Misc/PowerShell.cs b/mpv.net/Misc/PowerShell.cs index 7239604..4515a47 100644 --- a/mpv.net/Misc/PowerShell.cs +++ b/mpv.net/Misc/PowerShell.cs @@ -7,7 +7,7 @@ using System.Management.Automation.Runspaces; using System.Threading; using static mpvnet.Core; -using static NewLine; +using static mpvnet.NewLine; namespace mpvnet { diff --git a/mpv.net/Misc/Program.cs b/mpv.net/Misc/Program.cs index 4cf87d2..677c070 100644 --- a/mpv.net/Misc/Program.cs +++ b/mpv.net/Misc/Program.cs @@ -31,11 +31,11 @@ namespace mpvnet if (args.Length >= 2 && args[0] == "--reg-file-assoc") { if (args[1] == "audio") - FileAssociation.Register(App.AudioTypes); + FileAssociation.Register(Core.AudioTypes); else if (args[1] == "video") - FileAssociation.Register(App.VideoTypes); + FileAssociation.Register(Core.VideoTypes); else if (args[1] == "image") - FileAssociation.Register(App.ImageTypes); + FileAssociation.Register(Core.ImageTypes); else FileAssociation.Register(args.Skip(1).ToArray()); diff --git a/mpv.net/Misc/RegistryHelp.cs b/mpv.net/Misc/RegistryHelp.cs deleted file mode 100644 index 2ff753b..0000000 --- a/mpv.net/Misc/RegistryHelp.cs +++ /dev/null @@ -1,64 +0,0 @@ - -using System; -using Microsoft.Win32; -using System.Windows.Forms; - -public class RegistryHelp -{ - public static string ApplicationKey { get; } = @"HKCU\Software\" + Application.ProductName; - - public static void SetValue(string path, string name, object value) - { - using (RegistryKey regKey = GetRootKey(path).CreateSubKey(path.Substring(5), RegistryKeyPermissionCheck.ReadWriteSubTree)) - regKey.SetValue(name, value); - } - - public static string GetString(string path, string name, string defaultValue = "") - { - object value = GetValue(path, name, defaultValue); - return !(value is string) ? defaultValue : value.ToString(); - } - - public static int GetInt(string path, string name, int defaultValue = 0) - { - object value = GetValue(path, name, defaultValue); - return !(value is int) ? defaultValue : (int)value; - } - - public static object GetValue(string path, string name, object defaultValue = null) - { - using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5))) - return regKey == null ? null : regKey.GetValue(name, defaultValue); - } - - public static void RemoveKey(string path) - { - try - { - GetRootKey(path).DeleteSubKeyTree(path.Substring(5), false); - } - catch { } - } - - public static void RemoveValue(string path, string name) - { - try - { - using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5), true)) - if (regKey != null) - regKey.DeleteValue(name, false); - } - catch { } - } - - static RegistryKey GetRootKey(string path) - { - switch (path.Substring(0, 4)) - { - case "HKLM": return Registry.LocalMachine; - case "HKCU": return Registry.CurrentUser; - case "HKCR": return Registry.ClassesRoot; - default: throw new Exception(); - } - } -} \ No newline at end of file diff --git a/mpv.net/Resources/input.conf.txt b/mpv.net/Resources/input.conf.txt index cf676f3..d6b793f 100644 --- a/mpv.net/Resources/input.conf.txt +++ b/mpv.net/Resources/input.conf.txt @@ -141,8 +141,11 @@ Ctrl+t set ontop yes #menu: View > On Top > Enable Ctrl+T set ontop no #menu: View > On Top > Disable - Alt++ no-osd set window-scale 1.2 #menu: View > Window Size > Enlarge - Alt+- no-osd set window-scale 0.8 #menu: View > Window Size > Shrink + Alt++ script-message mpv.net scale-window 1.2 #menu: View > Window Size > Enlarge + Alt+- script-message mpv.net scale-window 0.8 #menu: View > Window Size > Shrink + Alt+0 set window-scale 0.5 #menu: View > Zoom > 50 % + Alt+1 set window-scale 1.0 #menu: View > Zoom > 100 % + Alt+2 set window-scale 2.0 #menu: View > Zoom > 200 % b cycle border #menu: View > Toggle Border i script-message mpv.net show-info #menu: View > File/Stream Info t script-binding stats/display-stats #menu: View > Show Statistics diff --git a/mpv.net/WPF/EverythingWindow.xaml.cs b/mpv.net/WPF/EverythingWindow.xaml.cs index 0bdab4c..4bea558 100644 --- a/mpv.net/WPF/EverythingWindow.xaml.cs +++ b/mpv.net/WPF/EverythingWindow.xaml.cs @@ -142,7 +142,7 @@ namespace mpvnet Everything_GetResultFullPathName(i, sb, (uint)sb.Capacity); string ext = sb.ToString().Ext(); - if (App.AudioTypes.Contains(ext) || App.VideoTypes.Contains(ext) || App.ImageTypes.Contains(ext)) + if (Core.AudioTypes.Contains(ext) || Core.VideoTypes.Contains(ext) || Core.ImageTypes.Contains(ext)) items.Add(sb.ToString()); if (items.Count > 100) diff --git a/mpv.net/WPF/SetupWindow.xaml.cs b/mpv.net/WPF/SetupWindow.xaml.cs index 45f483a..6811434 100644 --- a/mpv.net/WPF/SetupWindow.xaml.cs +++ b/mpv.net/WPF/SetupWindow.xaml.cs @@ -50,9 +50,9 @@ namespace mpvnet } catch {} } - void AddVideo_Click(object sender, RoutedEventArgs e) => RegFileAssoc(App.VideoTypes); - void AddAudio_Click(object sender, RoutedEventArgs e) => RegFileAssoc(App.AudioTypes); - void AddImage_Click(object sender, RoutedEventArgs e) => RegFileAssoc(App.ImageTypes); + void AddVideo_Click(object sender, RoutedEventArgs e) => RegFileAssoc(Core.VideoTypes); + void AddAudio_Click(object sender, RoutedEventArgs e) => RegFileAssoc(Core.AudioTypes); + void AddImage_Click(object sender, RoutedEventArgs e) => RegFileAssoc(Core.ImageTypes); void RemoveFileAssociations_Click(object sender, RoutedEventArgs e) { diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index 2ad7a5a..e4864c3 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -49,6 +49,10 @@ namespace mpvnet Hwnd = Handle; ConsoleHelp.Padding = 60; core.Init(); + core.Title = core.get_property_string("title"); + + if (core.Title != null && core.Title.EndsWith("} - mpv")) + core.Title = ""; if (App.GlobalMediaKeys) { @@ -60,6 +64,7 @@ namespace mpvnet core.Shutdown += Shutdown; core.VideoSizeChanged += VideoSizeChanged; + core.ScaleWindow += ScaleWindow; core.FileLoaded += FileLoaded; core.Idle += Idle; core.Seek += () => UpdateProgressBar(); @@ -75,6 +80,8 @@ namespace mpvnet core.observe_property_string("aid", PropChangeAid); core.observe_property_string("vid", PropChangeVid); + core.observe_property_string("title", PropChangeTitle); + core.observe_property_int("edition", PropChangeEdition); core.observe_property_double("window-scale", PropChangeWindowScale); @@ -84,7 +91,8 @@ namespace mpvnet AppDomain.CurrentDomain.UnhandledException += (sender, e) => App.ShowException(e.ExceptionObject); Application.ThreadException += (sender, e) => App.ShowException(e.Exception); Msg.SupportURL = "https://github.com/stax76/mpv.net#support"; - Text = "mpv.net " + Application.ProductVersion; + + Text = string.IsNullOrEmpty(core.Title) ? "mpv.net " + Application.ProductVersion : core.Title; TaskbarButtonCreatedMessage = RegisterWindowMessage("TaskbarButtonCreated"); ContextMenu = new ContextMenuStripEx(components); @@ -138,13 +146,27 @@ namespace mpvnet } } + void ScaleWindow(float value) + { + BeginInvoke(new Action(() => SetFormPosAndSize(value))); + } + + void WindowScale(double scale) + { + if (!WasShown()) + return; + + Size size = new Size((int)(core.VideoSize.Width * scale), (int)(core.VideoSize.Height * scale)); + SetSize(size, core.VideoSize, Screen.FromControl(this), false, false); + } + public MenuItem FindMenuItem(string text) => FindMenuItem(text, ContextMenu.Items); void Shutdown() => BeginInvoke(new Action(() => Close())); void Idle() { - BeginInvoke(new Action(() => Text = "mpv.net " + Application.ProductVersion)); + BeginInvoke(new Action(() => Text = string.IsNullOrEmpty(core.Title) ? "mpv.net " + Application.ProductVersion : core.Title)); } bool WasShown() => ShownTickCount != 0 && Environment.TickCount > ShownTickCount + 500; @@ -353,19 +375,31 @@ namespace mpvnet } height = Convert.ToInt32(height * scale); - int width = height * videoSize.Width / videoSize.Height; + SetSize(new Size(height * videoSize.Width / videoSize.Height, height), videoSize, screen); + } + + void SetSize(Size size, + Size videoSize, + Screen screen, + bool checkAutofitSmaller = true, + bool checkAutofitLarger = true) + { + int height = size.Height; + int width = size.Height * videoSize.Width / videoSize.Height; int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height); int maxWidth = screen.WorkingArea.Width - (Width - ClientSize.Width); - if (height < maxHeight * core.AutofitSmaller) + if (checkAutofitSmaller && (height < maxHeight * core.AutofitSmaller)) { height = Convert.ToInt32(maxHeight * core.AutofitSmaller); width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); } - if (height > maxHeight * core.AutofitLarger) + float autofitLarger = checkAutofitLarger ? core.AutofitLarger : 1; + + if (height > maxHeight * autofitLarger) { - height = Convert.ToInt32(maxHeight * core.AutofitLarger); + height = Convert.ToInt32(maxHeight * autofitLarger); width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); } @@ -399,8 +433,7 @@ namespace mpvnet if (top + rect.Height > maxBottom) top = maxBottom - rect.Height; - SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, - left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */); + SetWindowPos(Handle, IntPtr.Zero, left, top, rect.Width, rect.Height, 4); } public void CycleFullscreen(bool enabled) @@ -484,10 +517,15 @@ namespace mpvnet string path = core.get_property_string("path"); BeginInvoke(new Action(() => { - if (path.Contains("://")) - Text = core.get_property_string("media-title") + " - mpv.net " + Application.ProductVersion; + if (string.IsNullOrEmpty(core.Title)) + { + if (path.Contains("://")) + Text = core.get_property_string("media-title") + " - mpv.net " + Application.ProductVersion; + else + Text = path.FileName() + " - mpv.net " + Application.ProductVersion; + } else - Text = path.FileName() + " - mpv.net " + Application.ProductVersion; + Text = core.Title; int interval = (int)(core.Duration.TotalMilliseconds / 100); @@ -704,17 +742,15 @@ namespace mpvnet void PropChangeSid(string value) => core.Sid = value; void PropChangeVid(string value) => core.Vid = value; + + void PropChangeTitle(string value) => BeginInvoke(new Action(() => { + if (value != null && !value.EndsWith("} - mpv")) + Text = value; + })); void PropChangeEdition(int value) => core.Edition = value; - void PropChangeWindowScale(double value) - { - if (value != 1) - { - BeginInvoke(new Action(() => SetFormPosAndSize(value))); - core.command("no-osd set window-scale 1"); - } - } + void PropChangeWindowScale(double value) => BeginInvoke(new Action(() => WindowScale(value))); void PropChangeWindowMaximized() { diff --git a/mpv.net/mpv.net.csproj b/mpv.net/mpv.net.csproj index 0db6080..ec78c84 100644 --- a/mpv.net/mpv.net.csproj +++ b/mpv.net/mpv.net.csproj @@ -95,7 +95,6 @@ - License.txt @@ -129,7 +128,6 @@ - diff --git a/mpv.net/mpv/Core.cs b/mpv.net/mpv/Core.cs index 9555ca1..565612f 100644 --- a/mpv.net/mpv/Core.cs +++ b/mpv.net/mpv/Core.cs @@ -11,7 +11,7 @@ using System.Threading; using System.Windows.Forms; using static libmpv; -using static NewLine; +using static mpvnet.NewLine; using System.Globalization; @@ -20,6 +20,12 @@ namespace mpvnet public class Core { public static Core core { get; } = new Core(); + public static Core GetCore() => core; + + public static string[] VideoTypes { get; set; } = "264 265 asf avc avi avs dav flv h264 h265 hevc m2t m2ts m2v m4v mkv mov mp4 mpeg mpg mpv mts ts vob vpy webm wmv y4m".Split(' '); + public static string[] AudioTypes { get; set; } = "aac ac3 dts dtshd dtshr dtsma eac3 flac m4a mka mp2 mp3 mpa mpc ogg opus thd thd+ac3 w64 wav".Split(' '); + public static string[] ImageTypes { get; set; } = { "jpg", "bmp", "png", "gif" }; + public static string[] SubtitleTypes { get; } = { "srt", "ass", "idx", "sup", "ttxt", "ssa", "smi" }; public event Action LogMessageAsync; // log-message MPV_EVENT_LOG_MESSAGE public event Action EndFileAsync; // end-file MPV_EVENT_END_FILE @@ -69,6 +75,7 @@ namespace mpvnet public event Action VideoSizeChanged; public event Action VideoSizeChangedAsync; + public event Action ScaleWindow; public Dictionary> PropChangeActions { get; set; } = new Dictionary>(); public Dictionary>> IntPropChangeActions { get; set; } = new Dictionary>>(); @@ -88,12 +95,13 @@ namespace mpvnet public AutoResetEvent ShutdownAutoResetEvent { get; } = new AutoResetEvent(false); public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false); - public string InputConfPath { get => ConfigFolder + "input.conf"; } - public string ConfPath { get => ConfigFolder + "mpv.conf"; } - public string Sid { get; set; } = ""; public string Aid { get; set; } = ""; - public string Vid { get; set; } = ""; + public string ConfPath { get => ConfigFolder + "mpv.conf"; } public string GPUAPI { get; set; } = "auto"; + public string InputConfPath { get => ConfigFolder + "input.conf"; } + public string Sid { get; set; } = ""; + public string Title { get; set; } = ""; + public string Vid { get; set; } = ""; public bool WasInitialSizeSet; public bool Border { get; set; } = true; @@ -172,6 +180,7 @@ namespace mpvnet case "taskbar-progress": TaskbarProgress = value == "yes"; break; case "screen": Screen = Convert.ToInt32(value); break; case "gpu-api": GPUAPI = value; break; + case "title": Title = value; break; } if (AutofitLarger > 1) @@ -1077,7 +1086,7 @@ namespace mpvnet if (file.Ext() == "iso") LoadISO(file); - else if(App.SubtitleTypes.Contains(file.Ext())) + else if(Core.SubtitleTypes.Contains(file.Ext())) commandv("sub-add", file); else if (file.Ext().Length != 3 && File.Exists(Path.Combine(file, "BDMV\\index.bdmv"))) { @@ -1157,9 +1166,9 @@ namespace mpvnet List files = Directory.GetFiles(dir).ToList(); files = files.Where(file => - App.VideoTypes.Contains(file.Ext()) || - App.AudioTypes.Contains(file.Ext()) || - App.ImageTypes.Contains(file.Ext())).ToList(); + Core.VideoTypes.Contains(file.Ext()) || + Core.AudioTypes.Contains(file.Ext()) || + Core.ImageTypes.Contains(file.Ext())).ToList(); files.Sort(new StringLogicalComparer()); int index = files.IndexOf(path); @@ -1265,6 +1274,11 @@ namespace mpvnet return id; } + public void RaiseScaleWindow(float value) + { + ScaleWindow(value); + } + void ReadMetaData() { string path = get_property_string("path");