From 5d16d7b2d13de328e1a8e2d287c0c156042ee01f Mon Sep 17 00:00:00 2001 From: stax76 Date: Tue, 17 May 2022 15:05:00 +0200 Subject: [PATCH] support mpv idle property partly --- docs/Changelog.md | 9 ++++++--- docs/Manual.md | 12 +++++++----- src/Misc/App.cs | 3 +-- src/Misc/Player.cs | 12 ++++++++++-- src/Resources/editor_conf.txt | 10 +++++----- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index afb7cad..535e5b5 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,7 +1,10 @@ -- When input.conf is created on the very first start and - a script-opts folder does not exist, a script-opts folder is - created with defaults for osc and console. +- When input.conf is created on the very first start and a + script-opts folder does not exist, a script-opts folder + is created with defaults for osc and console. +- Support mpv idle property, see manual for remarks. +- libmpv shinchiro 2022-05-17 with idle fix + 5.9.0.0 Beta (2022-05-08) diff --git a/docs/Manual.md b/docs/Manual.md index aca83f5..519413c 100644 --- a/docs/Manual.md +++ b/docs/Manual.md @@ -446,10 +446,6 @@ Can be suppressed via shift key. Default: yes If the player is paused and another file is loaded, playback automatically resumes. -#### --keep-open-exit - -If set to yes and keep-open is set to no, mpv.net exits after the last file ends. -In mpv the idle property would be used, it's not possible for mpv.net to use the idle property. ### General @@ -790,7 +786,6 @@ https://mpv.io/manual/master/#window - [autofit-smaller](https://mpv.io/manual/master/#options-autofit-smaller) - [autofit](https://mpv.io/manual/master/#options-autofit) - mpv.net specific window features are documented in the [screen section](#screen). @@ -809,6 +804,13 @@ need an own implementation in mpv.net, so far implemented are: --vd=help --version +### Other Limitations + +The mpv property [idle](https://mpv.io/manual/master/#options-idle) can be +used and mpv.net functions accordingly, but Lua scripts see always `idle=yes` +because mpv.net has to set it to function correctly, this is a difficult +to overcome libmpv limitation. + ### mpv.net specific options diff --git a/src/Misc/App.cs b/src/Misc/App.cs index 2a0643c..49308a3 100644 --- a/src/Misc/App.cs +++ b/src/Misc/App.cs @@ -24,8 +24,8 @@ namespace mpvnet public static bool AutoLoadFolder { get; set; } = true; public static bool AutoPlay { get; set; } public static bool DebugMode { get; set; } + public static bool Exit { get; set; } public static bool IsTerminalAttached { get; } = Environment.GetEnvironmentVariable("_started_from_console") == "yes"; - public static bool KeepOpenExit { get; set; } public static bool Queue { get; set; } public static bool RememberVolume { get; set; } = true; public static bool RememberWindowPosition { get; set; } @@ -242,7 +242,6 @@ namespace mpvnet case "dark-theme": DarkTheme = value.Trim('\'', '"'); return true; case "debug-mode": DebugMode = value == "yes"; return true; case "image-file-extensions": CorePlayer.ImageTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; - case "keep-open-exit": KeepOpenExit = value == "yes"; return true; case "light-theme": LightTheme = value.Trim('\'', '"'); return true; case "minimum-aspect-ratio": MinimumAspectRatio = value.ToFloat(); return true; case "process-instance": ProcessInstance = value; return true; diff --git a/src/Misc/Player.cs b/src/Misc/Player.cs index e0e130d..190a4dd 100644 --- a/src/Misc/Player.cs +++ b/src/Misc/Player.cs @@ -142,7 +142,14 @@ namespace mpvnet SetPropertyString("config", "yes"); ProcessCommandLine(true); + mpv_error err = mpv_initialize(Handle); + string idle = GetPropertyString("idle"); + App.Exit = idle == "no" || idle == "once"; + + // otherwise shutdown is raised before media files are loaded, + // this means Lua scripts that use idle might not work correctly + SetPropertyString("idle", "yes"); if (err < 0) throw new Exception("mpv_initialize error" + BR2 + GetError(err) + BR); @@ -159,7 +166,7 @@ namespace mpvnet { ShowLogo(); - if (GetPropertyString("keep-open") == "no" && App.KeepOpenExit) + if (GetPropertyString("keep-open") == "no" && App.Exit) Core.CommandV("quit"); } }); @@ -985,7 +992,8 @@ namespace mpvnet var args = Environment.GetCommandLineArgs().Skip(1); string[] preInitProperties = { "input-terminal", "terminal", "input-file", "config", - "config-dir", "input-conf", "load-scripts", "scripts", "player-operation-mode" }; + "config-dir", "input-conf", "load-scripts", "scripts", "player-operation-mode", + "idle", "log-file", "msg-color", "dump-stats", "msg-level", "really-quiet" }; foreach (string i in args) { diff --git a/src/Resources/editor_conf.txt b/src/Resources/editor_conf.txt index 2c803e2..b115b36 100644 --- a/src/Resources/editor_conf.txt +++ b/src/Resources/editor_conf.txt @@ -513,7 +513,7 @@ filter = Playback help = Using no, mpv would terminate after the last file but mpv.net never terminates automatically. option = yes If the current file ends, go to the next file, keep the last file open. -option = no If the current file ends, go to the next file. If keep-open-exit is set to yes, mpv.net exits after the last file. +option = no If the current file ends, go to the next file. If idle is set to no, mpv.net exits after the last file. option = always Playback will never automatically advance to the next file. [setting] @@ -527,11 +527,11 @@ option = yes option = no [setting] -name = keep-open-exit -file = mpvnet -default = no +name = idle +file = mpv +default = yes filter = Playback -help = If set to yes and keep-open is set to no, mpv.net exits after the last file ends. In mpv the idle property would be used, it's not possible for mpv.net to use the idle property. +help = If set to no and keep-open is also set to no, mpv.net exits after the last file ends. In mpv the idle default is no and in mpv.net the default is yes. option = yes option = no