diff --git a/docs/changelog.md b/docs/changelog.md index c1574531..b7145373 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,13 +1,19 @@ # v7.0.0.4 Beta (2023-??-??) +- Command line parser supports list options with `-add` suffix. +- Fix window sometimes shown with wrong size. - Limited support for the mpv option `geometry`, it supports location in percent, - for size use `autofit`. Please read the instructions in the mpv.net manual or in the conf editor. -- Updated and improved manual. + for size use `autofit`. Read the instructions in the mpv.net manual or in the conf editor. +- Improved manual. +- Improved bindings. +- Conf editor reorganized according to options categories used in mpv manual. - mpv.net is available via command line package manager winget. - New libplacebo config editor options added. - The conf editor uses a newly developed combo box control (dropdown menu) - instead of radio buttons whenever an option has more than 3 items. + instead of radio buttons whenever an option has more than 3 items, + this improves the look and feel, usability and performance. + The navigation tree view was improved. - New zhongfly libmpv build. diff --git a/docs/manual.md b/docs/manual.md index 30454f0f..18059443 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -25,6 +25,7 @@ Table of contents * [Hidden Features](#hidden-features) * [Differences compared to mpv](#differences-compared-to-mpv) * [Environment Variables](#environment-variables) +* [user-data](#user-data) * [Context Menu Commands](#context-menu) @@ -269,12 +270,6 @@ Shows available [mpv input commands](https://mpv.io/manual/master/#list-of-input ### show-conf-editor Shows the conf editor. -### show-decoders -Shows available decoders. - -### show-demuxers -Shows available demuxers. - ### show-input-editor Shows the input editor. @@ -707,6 +702,18 @@ Environment Variables Directory where mpv.net looks for user settings. +user-data +--------- + +Script authors can access the following +[user-data](https://mpv.io/manual/master/#command-interface-user-data) properties: + +``` +user-data/frontend/name +user-data/frontend/version +user-data/frontend/process-path +``` + Context Menu Commands --------------------- diff --git a/src/MpvNet.Windows/Program.cs b/src/MpvNet.Windows/Program.cs index 48f81bb9..b80f6177 100644 --- a/src/MpvNet.Windows/Program.cs +++ b/src/MpvNet.Windows/Program.cs @@ -7,7 +7,6 @@ using MpvNet.Windows.UI; using MpvNet.Windows.Help; using MpvNet.Windows.WPF; -using System.Diagnostics; namespace MpvNet.Windows; @@ -97,10 +96,13 @@ static void Main() return; } - if (App.CommandLine.Contains("--o=")) + if (ProcessCommandLineArguments()) + Environment.GetCommandLineArgs(); + else if (App.CommandLine.Contains("--o=")) { App.AutoLoadFolder = false; Player.Init(IntPtr.Zero); + Player.ProcessCommandLineArgsPost(); Player.ProcessCommandLineFiles(); Player.SetPropertyString("idle", "no"); Player.EventLoop(); @@ -119,4 +121,48 @@ static void Main() Terminal.WriteError(ex); } } + + static bool ProcessCommandLineArguments() + { + foreach (string arg in Environment.GetCommandLineArgs().Skip(1)) + { + if (arg == "--profile=help") + { + Player.Init(IntPtr.Zero, false); + Console.WriteLine(Player.GetProfiles()); + Player.Destroy(); + return true; + } + else if (arg == "--vd=help" || arg == "--ad=help") + { + Player.Init(IntPtr.Zero, false); + Console.WriteLine(Player.GetDecoders()); + Player.Destroy(); + return true; + } + else if (arg == "--audio-device=help") + { + Player.Init(IntPtr.Zero, false); + Console.WriteLine(Player.GetPropertyOsdString("audio-device-list")); + Player.Destroy(); + return true; + } + else if (arg == "--input-keylist") + { + Player.Init(IntPtr.Zero, false); + Console.WriteLine(Player.GetPropertyString("input-key-list").Replace(",", BR)); + Player.Destroy(); + return true; + } + else if (arg == "--version") + { + Player.Init(IntPtr.Zero, false); + Console.WriteLine(AppClass.About); + Player.Destroy(); + return true; + } + } + + return false; + } } diff --git a/src/MpvNet.Windows/Resources/editor_conf.txt b/src/MpvNet.Windows/Resources/editor_conf.txt index fb4a5755..043b4317 100644 --- a/src/MpvNet.Windows/Resources/editor_conf.txt +++ b/src/MpvNet.Windows/Resources/editor_conf.txt @@ -44,6 +44,21 @@ file = mpvnet directory = General help = Used menu syntax for defining the context menu in input.conf.\nmpv.net by default uses '#menu:', uosc uses '#!' by default. +name = video-sync +file = mpv +default = audio +directory = General +help = How the player synchronizes audio and video.\n\nFor more information visit: +url = https://mpv.io/manual/master/#options-video-sync +option = audio +option = display-resample +option = display-resample-vdrop +option = display-resample-desync +option = display-vdrop +option = display-adrop +option = display-desync +option = desync + name = debug-mode file = mpvnet default = no @@ -85,8 +100,8 @@ option = nvdec-copy copies video back to system RAM name = gpu-api file = mpv default = auto -directory = Video -help = Controls which type of graphics APIs will be accepted. Auto uses d3d11, it should only be changed in case of problems, Vulkan is not recommended. +directory = Video/Render Options +help = Controls which type of graphics APIs will be accepted. On Windows this defaults to d3d11 and should not be changed without a good reason. option = auto Use any available API option = d3d11 Allow only gpu-context=d3d11 option = opengl Allow only OpenGL (requires OpenGL 2.1+ or GLES 2.0+) @@ -95,7 +110,7 @@ option = vulkan Allow only Vulkan name = gpu-context file = mpv default = auto -directory = Video +directory = Video/Render Options option = auto auto-select option = d3d11 Win32, with native Direct3D 11 rendering. option = angle Direct3D11 through the OpenGL ES translation layer ANGLE. This supports almost everything the win backend does (if the ANGLE build is new enough). @@ -103,33 +118,10 @@ option = win Win32/WGL option = dxinterop (experimental) Win32, using WGL for rendering and Direct3D 9Ex for presentation. Works on Nvidia and AMD. Newer Intel chips with the latest drivers may also work. option = winvk VK_KHR_win32_surface -name = video-sync -file = mpv -default = audio -directory = Video -help = How the player synchronizes audio and video.\n\nFor more information visit: -url = https://mpv.io/manual/master/#options-video-sync -option = audio -option = display-resample -option = display-resample-vdrop -option = display-resample-desync -option = display-vdrop -option = display-adrop -option = display-desync -option = desync - -name = d3d11va-zero-copy -file = mpv -default = no -directory = Video -url = https://mpv.io/manual/master/#options-d3d11va-zero-copy -option = yes -option = no - name = scale file = mpv default = lanczos -directory = Video/Render Options +directory = Video/Render Options/Scaling help = The GPU renderer filter function to use when upscaling video. There are some more filters, but most are not as useful. For a complete list, pass help as value, e.g.: mpv --scale=help url = https://mpv.io/manual/master/#options-scale option = bilinear @@ -143,7 +135,7 @@ option = oversample name = cscale file = mpv default = bilinear -directory = Video/Render Options +directory = Video/Render Options/Scaling help = As scale, but for interpolating chroma information. If the image is not subsampled, this option is ignored entirely. url = https://mpv.io/manual/master/#options-cscale option = bilinear @@ -157,7 +149,7 @@ option = oversample name = dscale file = mpv default = lanczos -directory = Video/Render Options +directory = Video/Render Options/Scaling help = Like scale, but apply these filters on downscaling instead. \nIf no option is selected, it will keep the same with the upscaler. url = https://mpv.io/manual/master/#options-dscale option = bilinear @@ -168,20 +160,10 @@ option = ewa_lanczossharp option = mitchell option = oversample -name = dither-depth -file = mpv -default = no -directory = Video/Render Options -help = Set dither target depth to N. Note that the depth of the connected video display device cannot be detected. Often, LCD panels will do dithering on their own, which conflicts with this option and leads to ugly output. -option = no Disable any dithering done by mpv. -option = auto Automatic selection. If output bit depth cannot be detected, 8 bits per component are assumed. -option = 8 Dither to 8 bit output. -option = 10 Dither to 10 bit output. - name = correct-downscaling file = mpv default = no -directory = Video/Render Options +directory = Video/Render Options/Scaling help = When using convolution based filters, extend the filter size when downscaling. Increases quality, but reduces performance while downscaling.\n\nThis will perform slightly sub-optimally for anamorphic video (but still better than without it) since it will extend the size to match only the milder of the scale factors between the axes. option = yes option = no @@ -189,11 +171,21 @@ option = no name = sigmoid-upscaling file = mpv default = no -directory = Video/Render Options +directory = Video/Render Options/Scaling help = When upscaling, use a sigmoidal color transform to avoid emphasizing ringing artifacts. This also implies linear-scaling. option = yes option = no +name = dither-depth +file = mpv +default = no +directory = Video/Render Options +help = Set dither target depth to N. Note that the depth of the connected video display device cannot be detected. Often, LCD panels will do dithering on their own, which conflicts with this option and leads to ugly output. +option = no Disable any dithering done by mpv. +option = auto Automatic selection. If output bit depth cannot be detected, 8 bits per component are assumed. +option = 8 Dither to 8 bit output. +option = 10 Dither to 10 bit output. + name = deband file = mpv default = no @@ -219,6 +211,14 @@ url = https://mpv.io/manual/master/#options-allow-delayed-peak-detect option = yes option = no +name = d3d11va-zero-copy +file = mpv +default = no +directory = Video/Render Options +url = https://mpv.io/manual/master/#options-d3d11va-zero-copy +option = yes +option = no + name = background file = mpv directory = Video/Render Options @@ -242,11 +242,10 @@ option = high_quality Reset all everything to high quality presets (where avail name = upscaler file = libplacebo directory = Video/libplacebo/Scaling -default = default -help = Sets the filter used for upscaling. Defaults to lanczos. +default = lanczos +help = Sets the filter used for upscaling. url = https://libplacebo.org/options/#upscalerfilter option-name-width = 135 -option = default Default. option = none No filter, only use basic GPU texture sampling. option = nearest Nearest-neighbour (box) sampling (very fast). option = bilinear Bilinear sampling (very fast). @@ -263,7 +262,7 @@ name = downscaler file = libplacebo directory = Video/libplacebo/Scaling default = hermite -help = Sets the filter used for downscaling. Defaults to hermite. The most relevant options, roughly ordered from fastest to slowest. +help = Sets the filter used for downscaling. The most relevant options, roughly ordered from fastest to slowest. option = none Use the same filter as specified for upscaler option = box Box averaging (very fast) option = hermite Hermite-weighted averaging (fast) @@ -323,7 +322,7 @@ help = <0.0..1.0> Antiringing strength to use for all filters. A value of 0.0 di name = deband file = libplacebo directory = Video/libplacebo/Debanding -help = Enables debanding. +help = Enables debanding using libplacebo. default = no option = yes option = no @@ -509,10 +508,16 @@ type = color directory = Subtitle help = See sub-color. Color used for sub text background. You can use sub-shadow-offset to change its size relative to the text. +name = title +file = mpv +directory = Window +width = 400 +help = Set the window title. This is used for the video window, and if possible, also sets the audio stream title. Properties are expanded. Warning! There is a danger of this causing significant CPU usage, depending on the properties used. + name = fullscreen file = mpv default = no -directory = Screen +directory = Window help = Start the player in fullscreen mode. option = yes option = no @@ -520,76 +525,84 @@ option = no name = border file = mpv default = yes -directory = Screen +directory = Window help = Show window with decoration (titlebar, border). option = yes option = no name = screen file = mpv -directory = Screen +directory = Window help = <0-32> In multi-monitor configurations (i.e. a single desktop that spans across multiple displays), this option tells mpv which screen to display the video on. +name = taskbar-progress +file = mpv +default = yes +directory = Window +help = Show progress in taskbar. +option = yes +option = no + name = osd-playing-msg file = mpv width = 300 -directory = Screen +directory = Window type = string help = Show a message on OSD when playback starts. The string is expanded for properties, e.g. osd-playing-msg='file: ${filename}' will show the message file: followed by a space and the currently played filename. For more information visit: url = https://mpv.io/manual/master/#property-expansion name = osd-font-size file = mpv -directory = Screen +directory = Window help = Specify the OSD font size. See sub-font-size for details. Default: 55 name = osd-duration file = mpv -directory = Screen +directory = Window help = Set the duration of the OSD messages in ms. Default: 1000 name = osd-scale-by-window file = mpv default = yes -directory = Screen +directory = Window help = Whether to scale the OSD with the window size. If this is disabled, osd-font-size and other OSD options that use scaled pixels are always in actual pixels. The effect is that changing the window size won't change the OSD font size. option = yes option = no name = autofit file = mpv -directory = Screen +directory = Window help = Initial window height in percent. Default: 60 name = autofit-smaller file = mpv -directory = Screen +directory = Window help = Minimum window height in percent. Default: 10 name = autofit-larger file = mpv -directory = Screen +directory = Window help = Maximum window height in percent. Default: 80 name = autofit-image file = mpvnet -directory = Screen +directory = Window help = Initial window height in percent for image files. Default: 80 name = autofit-audio file = mpvnet -directory = Screen +directory = Window help = Initial window height in percent for audio files. Default: 70 name = geometry file = mpvnet -directory = Screen +directory = Window help = Initial window location in percent. Default: 50:50 (centered)\n\nx=0 docks the window to the left side.\nx=100 docks the window to the right side.\ny=0 docks the window to the top side.\ny=100 docks the window to the bottom side. name = start-size file = mpvnet default = height-session -directory = Screen +directory = Window help = Setting to remember the window size. (mpv.net option) option = width-session Window width is remembered in the current session option = width-always Window width is always remembered @@ -602,25 +615,25 @@ option = always Window size is always remembered name = keepaspect-window file = mpv default = yes -directory = Screen +directory = Window help = keepaspect-window will lock the window size to the video aspect. Default: yes option = yes option = no name = minimum-aspect-ratio file = mpvnet -directory = Screen +directory = Window help = Minimum aspect ratio of the window. Useful to force a wider window and therefore a larger OSC. (mpv.net option) name = minimum-aspect-ratio-audio file = mpvnet -directory = Screen +directory = Window help = Same as minimum-aspect-ratio but used for audio files. name = remember-window-position file = mpvnet default = no -directory = Screen +directory = Window help = Save the window position on exit. (mpv.net option) option = yes option = no @@ -628,7 +641,7 @@ option = no name = snap-window file = mpv default = no -directory = Screen +directory = Window help = Snap the player window to screen edges. option = yes option = no @@ -636,27 +649,8 @@ option = no name = window-maximized file = mpv default = no -directory = Screen -help = Start with a maximized window. -option = yes -option = no - -name = start-threshold -file = mpvnet -directory = Screen -help = Threshold in milliseconds to wait for libmpv returning the video resolution before the window is shown, otherwise default dimensions are used as defined by autofit and start-size. Default: 1500 (mpv.net option) - -name = title -file = mpv directory = Window -width = 400 -help = Set the window title. This is used for the video window, and if possible, also sets the audio stream title. Properties are expanded. Warning! There is a danger of this causing significant CPU usage, depending on the properties used. - -name = taskbar-progress -file = mpv -default = yes -directory = Playback -help = Show progress in taskbar. +help = Start with a maximized window. option = yes option = no diff --git a/src/MpvNet.Windows/WPF/ConfWindow.xaml b/src/MpvNet.Windows/WPF/ConfWindow.xaml index 0ea61b79..46332565 100644 --- a/src/MpvNet.Windows/WPF/ConfWindow.xaml +++ b/src/MpvNet.Windows/WPF/ConfWindow.xaml @@ -28,8 +28,8 @@ - - + + @@ -40,7 +40,7 @@ - + @@ -135,12 +135,12 @@ diff --git a/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs b/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs index e029d5dd..dbb5c961 100644 --- a/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs +++ b/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs @@ -48,7 +48,7 @@ public ConfWindow() SelectNodeFromSearchText(node); foreach (var node in Nodes) - ExpandNode(node); + node.IsExpanded = true; } public Theme? Theme => Theme.Current; @@ -134,7 +134,9 @@ void LoadSettings() foreach (ConfItem item in ConfItems) { - if (setting.Name == item.Name && item.Section == "" && !item.IsSectionItem) + if (setting.Name == item.Name && + setting.File == item.File && + item.Section == "" && !item.IsSectionItem) { setting.Value = item.Value; setting.StartValue = setting.Value; @@ -242,7 +244,7 @@ void LoadConf(string file) { if (!isSectionItem && comment != "" && comment != "\r\n") ConfItems.Add(new ConfItem() { - Comment = comment, File = System.IO.Path.GetFileNameWithoutExtension(file)}); + Comment = comment, File = Path.GetFileNameWithoutExtension(file)}); section = line.Substring(0, line.IndexOf("]") + 1); comment = ""; @@ -254,7 +256,7 @@ void LoadConf(string file) line += "=yes"; ConfItem item = new(); - item.File = System.IO.Path.GetFileNameWithoutExtension(file); + item.File = Path.GetFileNameWithoutExtension(file); item.IsSectionItem = isSectionItem; item.Comment = comment; comment = ""; @@ -501,6 +503,7 @@ void SelectNodeFromSearchText(NodeViewModel node) if (node.Path + ":" == SearchText) { node.IsSelected = true; + node.IsExpanded = true; return; } @@ -517,14 +520,6 @@ void UnselectNode(NodeViewModel node) UnselectNode(it); } - void ExpandNode(NodeViewModel node) - { - node.IsExpanded = true; - - foreach (var it in node.Children) - ExpandNode(it); - } - [RelayCommand] void ShowMpvNetSpecificSettings() => SearchText = "mpv.net"; [RelayCommand] void PreviewMpvConfFile() => Msg.ShowInfo(GetContent("mpv")); diff --git a/src/MpvNet.Windows/WinForms/MainForm.cs b/src/MpvNet.Windows/WinForms/MainForm.cs index e103822e..6abca207 100644 --- a/src/MpvNet.Windows/WinForms/MainForm.cs +++ b/src/MpvNet.Windows/WinForms/MainForm.cs @@ -68,8 +68,7 @@ public MainForm() GuiCommand.Current.WindowScaleNet += GuiCommand_WindowScaleNet; GuiCommand.Current.ShowMenu += GuiCommand_ShowMenu; - if (Player.GPUAPI != "vulkan") - Init(); + Init(); _taskbarButtonCreatedMessage = RegisterWindowMessage("TaskbarButtonCreated"); @@ -163,6 +162,7 @@ void Init() Player.ObservePropertyDouble("window-scale", PropChangeWindowScale); + Player.ProcessCommandLineArgsPost(); Player.ProcessCommandLineFiles(); } @@ -677,10 +677,9 @@ void SetSize(int width, int height, Screen screen, bool checkAutofit = true, boo int minTop = screens.Select(val => WinApiHelp.GetWorkingArea(Handle, val.WorkingArea).Y).Min(); int maxBottom = screens.Select(val => WinApiHelp.GetWorkingArea(Handle, val.WorkingArea).Bottom).Max(); - if (load && App.CommandLine.Contains(" --geometry=")) + if (load && CommandLine.Contains("geometry")) { - string geometryString = Environment.GetCommandLineArgs() - .Where(i => i.StartsWith("--geometry=")).First().Substring(11); + string geometryString = CommandLine.GetValue("geometry"); var geometry = ParseGeometry(geometryString, WinApiHelp.GetWorkingArea( Handle, Screen.FromHandle(Handle).WorkingArea), width, height); @@ -1258,10 +1257,6 @@ void Player_Pause() protected override void OnLoad(EventArgs e) { base.OnLoad(e); - - if (Player.GPUAPI != "vulkan") - Player.VideoSizeAutoResetEvent.WaitOne(App.StartThreshold); - _lastCycleFullscreen = Environment.TickCount; SetFormPosAndSize(false, true, true); } @@ -1276,9 +1271,6 @@ protected override void OnShown(EventArgs e) { base.OnShown(e); - if (Player.GPUAPI == "vulkan") - Init(); - if (WindowState == FormWindowState.Maximized) Player.SetPropertyBool("window-maximized", true); diff --git a/src/MpvNet/App.cs b/src/MpvNet/App.cs index e6e7b81f..c6ebe81f 100644 --- a/src/MpvNet/App.cs +++ b/src/MpvNet/App.cs @@ -10,7 +10,6 @@ namespace MpvNet; public class AppClass { public List TempFiles { get; } = new (); - public Dictionary CommandLineArguments { get; } = new (); public string ConfPath { get => Player.ConfigFolder + "mpvnet.conf"; } public string ProcessInstance { get; set; } = "single"; @@ -31,7 +30,6 @@ public class AppClass public bool RememberVolume { get; set; } = true; public bool RememberWindowPosition { get; set; } - public int StartThreshold { get; set; } = 1500; public int RecentCount { get; set; } = 15; public float AutofitAudio { get; set; } = 0.7f; @@ -155,7 +153,6 @@ public bool ProcessProperty(string name, string value, bool writeError = false) case "remember-volume": RememberVolume = value == "yes"; return true; case "remember-window-position": RememberWindowPosition = value == "yes"; return true; case "start-size": StartSize = value; return true; - case "start-threshold": StartThreshold = value.ToInt(1500); return true; case "video-file-extensions": FileTypes.Video = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; default: diff --git a/src/MpvNet/CommandLine.cs b/src/MpvNet/CommandLine.cs new file mode 100644 index 00000000..72bbd9b1 --- /dev/null +++ b/src/MpvNet/CommandLine.cs @@ -0,0 +1,73 @@ + +namespace MpvNet; + +public class CommandLine +{ + static List? _arguments; + + public static List Arguments + { + get + { + if (_arguments != null) + return _arguments; + + _arguments = new(); + + foreach (string i in Environment.GetCommandLineArgs().Skip(1)) + { + string arg = i; + + if (!arg.StartsWith("--")) + continue; + + if (!arg.Contains('=')) + { + if (arg.Contains("--no-")) + { + arg = arg.Replace("--no-", "--"); + arg += "=no"; + } + else + arg += "=yes"; + } + + string left = arg[2..arg.IndexOf("=")]; + string right = arg[(left.Length + 3)..]; + + if (string.IsNullOrEmpty(left)) + continue; + + switch (left) + { + case "script": left = "scripts"; break; + case "audio-file": left = "audio-files"; break; + case "sub-file": left = "sub-files"; break; + case "external-file": left = "external-files"; break; + } + + _arguments.Add(new StringPair(left, right)); + } + + return _arguments; + } + } + + public static bool Contains(string name) + { + foreach (StringPair pair in Arguments) + if (pair.Name == name) + return true; + + return false; + } + + public static string GetValue(string name) + { + foreach (StringPair pair in Arguments) + if (pair.Name == name) + return pair.Value; + + return ""; + } +} diff --git a/src/MpvNet/InputHelp.cs b/src/MpvNet/InputHelp.cs index 877efb9e..7a7bfc41 100644 --- a/src/MpvNet/InputHelp.cs +++ b/src/MpvNet/InputHelp.cs @@ -125,8 +125,6 @@ public static List GetDefaults() new (_("View") + " > " + _("More"), _("Show Console"), "script-binding console/enable", "`"), new (_("View") + " > " + _("More"), _("Show Audio Devices"), "script-message-to mpvnet show-audio-devices"), new (_("View") + " > " + _("More"), _("Show Commands"), "script-message-to mpvnet show-commands", "F2"), - new (_("View") + " > " + _("More"), _("Show Demuxers"), "script-message-to mpvnet show-demuxers"), - new (_("View") + " > " + _("More"), _("Show Decoders"), "script-message-to mpvnet show-decoders"), new (_("View") + " > " + _("More"), _("Show Bindings"), "script-message-to mpvnet show-bindings"), new (_("Window"), _("Fullscreen"), "cycle fullscreen", "Enter"), diff --git a/src/MpvNet/MpvClient.cs b/src/MpvNet/MpvClient.cs index e5b4f3a8..28b4c2fe 100644 --- a/src/MpvNet/MpvClient.cs +++ b/src/MpvNet/MpvClient.cs @@ -64,7 +64,7 @@ public void EventLoop() OnEndFile(data); } break; - case mpv_event_id.MPV_EVENT_FILE_LOADED: + case mpv_event_id.MPV_EVENT_FILE_LOADED: // triggered after MPV_EVENT_START_FILE OnFileLoaded(); break; case mpv_event_id.MPV_EVENT_PROPERTY_CHANGE: @@ -82,7 +82,7 @@ public void EventLoop() case mpv_event_id.MPV_EVENT_COMMAND_REPLY: OnCommandReply(); break; - case mpv_event_id.MPV_EVENT_START_FILE: + case mpv_event_id.MPV_EVENT_START_FILE: // triggered before MPV_EVENT_FILE_LOADED OnStartFile(); break; case mpv_event_id.MPV_EVENT_AUDIO_RECONFIG: diff --git a/src/MpvNet/Player.cs b/src/MpvNet/Player.cs index c13d9489..44ce40e4 100644 --- a/src/MpvNet/Player.cs +++ b/src/MpvNet/Player.cs @@ -50,7 +50,6 @@ public class MainPlayer : MpvClient public float AutofitLarger { get; set; } = 0.8f; public AutoResetEvent ShutdownAutoResetEvent { get; } = new AutoResetEvent(false); - public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false); public nint MainHandle { get; set; } public List MediaTracks { get; set; } = new List(); public List BluRayTitles { get; } = new List(); @@ -64,7 +63,7 @@ public class MainPlayer : MpvClient public event Action? PlaylistPosChanged; public event Action? VideoSizeChanged; - public void Init(IntPtr formHandle) + public void Init(IntPtr formHandle, bool processCommandLineArguments = true) { App.ApplyShowMenuFix(); @@ -104,17 +103,18 @@ public void Init(IntPtr formHandle) SetPropertyString("force-window", "yes"); SetPropertyString("config-dir", ConfigFolder); SetPropertyString("config", "yes"); - + UsedInputConfContent = App.InputConf.GetContent(); if (!string.IsNullOrEmpty(UsedInputConfContent)) SetPropertyString("input-conf", @"memory://" + UsedInputConfContent); - ProcessCommandLineArgs(); + if (processCommandLineArguments) + ProcessCommandLineArgs(); - if (App.CommandLineArguments.ContainsKey("config-dir")) + if (CommandLine.Contains("config-dir")) { - string configDir = App.CommandLineArguments["config-dir"]; + string configDir = CommandLine.GetValue("config-dir"); string fullPath = System.IO.Path.GetFullPath(configDir); App.InputConf.Path = fullPath.AddSep() + "input.conf"; string content = App.InputConf.GetContent(); @@ -151,16 +151,20 @@ public void Init(IntPtr formHandle) // this means Lua scripts that use idle might not work correctly SetPropertyString("idle", "yes"); - ObservePropertyString("path", value => Path = value); - ObservePropertyBool("pause", value => { Paused = value; Pause?.Invoke(); }); - ObservePropertyInt("video-rotate", value => { - VideoRotate = value; - UpdateVideoSize("dwidth", "dheight"); + VideoRotate = GetPropertyInt("video-rotate"); + + ObservePropertyInt("video-rotate", value => + { + if (VideoRotate != value) + { + VideoRotate = value; + UpdateVideoSize("dwidth", "dheight"); + } }); ObservePropertyInt("playlist-pos", value => { @@ -172,9 +176,6 @@ public void Init(IntPtr formHandle) CommandV("quit"); }); - if (!GetPropertyBool("osd-scale-by-window")) - App.StartThreshold = 0; - Initialized?.Invoke(); } @@ -315,19 +316,18 @@ public Dictionary Conf { void UpdateVideoSize(string w, string h) { - Size size = new Size(GetPropertyInt(w), GetPropertyInt(h)); - - if (size.Width == 0 || size.Height == 0) + if (string.IsNullOrEmpty(Path)) return; + Size size = new Size(GetPropertyInt(w), GetPropertyInt(h)); + if (VideoRotate == 90 || VideoRotate == 270) size = new Size(size.Height, size.Width); - if (VideoSize != size) + if (size != VideoSize && size != Size.Empty) { VideoSize = size; VideoSizeChanged?.Invoke(size); - VideoSizeAutoResetEvent.Set(); } } @@ -357,24 +357,27 @@ protected override void OnLogMessage(mpv_event_log_message data) base.OnLogMessage(data); } - protected override void OnVideoReconfig() - { - UpdateVideoSize("dwidth", "dheight"); - base.OnVideoReconfig(); - } - protected override void OnEndFile(mpv_event_end_file data) { base.OnEndFile(data); FileEnded = true; } + protected override void OnVideoReconfig() + { + UpdateVideoSize("dwidth", "dheight"); + base.OnVideoReconfig(); + } + + // executed before OnFileLoaded protected override void OnStartFile() { + Path = GetPropertyString("path"); base.OnStartFile(); TaskHelp.Run(LoadFolder); } + // executed after OnStartFile protected override void OnFileLoaded() { Duration = TimeSpan.FromSeconds(GetPropertyDouble("duration")); @@ -382,13 +385,8 @@ protected override void OnFileLoaded() if (App.StartSize == "video") WasInitialSizeSet = false; - string path = GetPropertyString("path"); - - if (!FileTypes.Video.Contains(path.Ext()) || FileTypes.Audio.Contains(path.Ext())) - { + if (!FileTypes.Video.Contains(Path.Ext()) || FileTypes.Audio.Contains(Path.Ext())) UpdateVideoSize("width", "height"); - VideoSizeAutoResetEvent.Set(); - } TaskHelp.Run(UpdateTracks); @@ -417,75 +415,28 @@ void ProcessBluRayLogMessage(string msg) public void ProcessCommandLineArgs() { - foreach (string i in Environment.GetCommandLineArgs().Skip(1)) + foreach (var pair in CommandLine.Arguments) { - string arg = i; - - if (!arg.StartsWith("--")) - continue; - - if (arg == "--profile=help") - { - Console.WriteLine(GetProfiles()); - continue; - } - else if (arg == "--vd=help" || arg == "--ad=help") - { - Console.WriteLine(GetDecoders()); - continue; - } - else if (arg == "--audio-device=help") - { - Console.WriteLine(GetPropertyOsdString("audio-device-list")); - continue; - } - else if (arg == "--version") - { - Console.WriteLine(AppClass.About); + if (pair.Name.EndsWith("-add")) continue; - } - else if (arg == "--input-keylist") - { - Console.WriteLine(GetPropertyString("input-key-list").Replace(",", BR)); - continue; - } - else if (arg.StartsWith("--command=")) - { - Command(arg[10..]); - continue; - } - - if (!arg.Contains('=')) - { - if (arg.Contains("--no-")) - { - arg = arg.Replace("--no-", "--"); - arg += "=no"; - } - else - arg += "=yes"; - } - string left = arg[2..arg.IndexOf("=")]; - string right = arg[(left.Length + 3)..]; + ProcessProperty(pair.Name, pair.Value); - if (string.IsNullOrEmpty(left)) - continue; + if (!App.ProcessProperty(pair.Name, pair.Value)) + SetPropertyString(pair.Name, pair.Value); + } + } - switch (left) + public void ProcessCommandLineArgsPost() + { + foreach (var pair in CommandLine.Arguments) + { + if (pair.Name.EndsWith("-add")) { - case "script": left = "scripts"; break; - case "audio-file": left = "audio-files"; break; - case "sub-file": left = "sub-files"; break; - case "external-file": left = "external-files"; break; + string name = pair.Name[..^4]; + string separator = name.Contains("-file") || name.Contains("-path") ? ";" : ","; + SetPropertyString(name, GetPropertyString(name) + separator + pair.Value); } - - App.CommandLineArguments[left] = right; - - ProcessProperty(left, right); - - if (!App.ProcessProperty(left, right)) - SetPropertyString(left, right); } } @@ -506,12 +457,6 @@ public void ProcessCommandLineFiles() Command("playlist-shuffle"); SetPropertyInt("playlist-pos", 0); } - - if (files.Count == 0 || files[0].Contains("://")) - { - VideoSizeChanged?.Invoke(VideoSize); - VideoSizeAutoResetEvent.Set(); - } } public DateTime LastLoad; diff --git a/src/MpvNet/Properties/launchSettings.json b/src/MpvNet/Properties/launchSettings.json new file mode 100644 index 00000000..956a839c --- /dev/null +++ b/src/MpvNet/Properties/launchSettings.json @@ -0,0 +1,7 @@ +{ + "profiles": { + "MpvNet": { + "commandName": "Project" + } + } +} \ No newline at end of file diff --git a/src/MpvNet.Windows/StringPair.cs b/src/MpvNet/StringPair.cs similarity index 87% rename from src/MpvNet.Windows/StringPair.cs rename to src/MpvNet/StringPair.cs index 51989a75..c89223f0 100644 --- a/src/MpvNet.Windows/StringPair.cs +++ b/src/MpvNet/StringPair.cs @@ -1,4 +1,5 @@ -namespace MpvNet.Windows; + +namespace MpvNet; public class StringPair {