From bc0fc2a29d6b92615cf9976b414a6906c546a459 Mon Sep 17 00:00:00 2001 From: stax76 Date: Thu, 19 May 2022 23:17:23 +0200 Subject: [PATCH] Fix auto-play not working with user scripts --- docs/Changelog.md | 1 + src/Misc/Commands.cs | 7 +------ src/Misc/MainForm.cs | 20 +++++++++----------- src/Misc/Player.cs | 27 ++++++++++++++++++++------- src/Resources/editor_conf.txt | 2 +- src/Resources/input.conf.txt | 10 +++++----- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 535e5b5..2a1284f 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,4 +1,5 @@ +- Fix auto-play not working with user scripts. - 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. diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs index c6d6d95..39a50dc 100644 --- a/src/Misc/Commands.cs +++ b/src/Misc/Commands.cs @@ -515,12 +515,7 @@ namespace mpvnet CommandPaletteItem item = new CommandPaletteItem() { Text = file.FileName(), - Action = () => { - Core.SetPropertyInt("playlist-pos", index); - - if (App.AutoPlay && Core.Paused) - Core.SetPropertyBool("pause", false); - } + Action = () => Core.SetPropertyInt("playlist-pos", index) }; items.Add(item); diff --git a/src/Misc/MainForm.cs b/src/Misc/MainForm.cs index 449534f..3eb6ed4 100644 --- a/src/Misc/MainForm.cs +++ b/src/Misc/MainForm.cs @@ -45,14 +45,15 @@ namespace mpvnet { Instance = this; - Core.Shutdown += Core_Shutdown; - Core.ShowMenu += Core_ShowMenu; - Core.VideoSizeChanged += Core_VideoSizeChanged; - Core.ScaleWindow += Core_ScaleWindow; - Core.WindowScale += Core_WindowScale; Core.FileLoaded += Core_FileLoaded; - Core.Seek += () => UpdateProgressBar(); + Core.Pause += Core_Pause; Core.PlaylistPosChanged += (value) => SetTitle(); + Core.ScaleWindow += Core_ScaleWindow; + Core.Seek += () => UpdateProgressBar(); + Core.ShowMenu += Core_ShowMenu; + Core.Shutdown += Core_Shutdown; + Core.VideoSizeChanged += Core_VideoSizeChanged; + Core.WindowScale += Core_WindowScale; if (Core.GPUAPI != "vulkan") Init(); @@ -126,7 +127,6 @@ namespace mpvnet Core.ObservePropertyBool("fullscreen", PropChangeFullscreen); Core.ObservePropertyBool("keepaspect-window", value => Core.KeepaspectWindow = value); Core.ObservePropertyBool("ontop", PropChangeOnTop); - Core.ObservePropertyBool("pause", PropChangePause); Core.ObservePropertyString("sid", PropChangeSid); Core.ObservePropertyString("aid", PropChangeAid); @@ -1016,13 +1016,11 @@ namespace mpvnet })); } - void PropChangePause(bool paused) + void Core_Pause() { - Core.Paused = paused; - if (Taskbar != null && Core.TaskbarProgress) { - if (paused) + if (Core.Paused) Taskbar.SetState(TaskbarStates.Paused); else Taskbar.SetState(TaskbarStates.Normal); diff --git a/src/Misc/Player.cs b/src/Misc/Player.cs index 190a4dd..bbc9a92 100644 --- a/src/Misc/Player.cs +++ b/src/Misc/Player.cs @@ -53,6 +53,7 @@ namespace mpvnet public event Action Initialized; public event Action InitializedAsync; + public event Action Pause; public event Action ShowMenu; public event Action ScaleWindow; public event Action WindowScale; @@ -144,6 +145,10 @@ namespace mpvnet ProcessCommandLine(true); mpv_error err = mpv_initialize(Handle); + + if (err < 0) + throw new Exception("mpv_initialize error" + BR2 + GetError(err) + BR); + string idle = GetPropertyString("idle"); App.Exit = idle == "no" || idle == "once"; @@ -151,8 +156,10 @@ namespace mpvnet // 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); + ObservePropertyBool("pause", value => { + Paused = value; + Pause(); + }); ObservePropertyInt("video-rotate", value => { VideoRotate = value; @@ -171,6 +178,13 @@ namespace mpvnet } }); + ObservePropertyString("script-opts", value => { + if (value.ContainsEx("osc-visibility=never")) + HideLogo(); + else if (GetPropertyInt("playlist-pos") == -1) + ShowLogo(); + }); + Initialized?.Invoke(); InvokeAsync(InitializedAsync); } @@ -463,7 +477,11 @@ namespace mpvnet break; case mpv_event_id.MPV_EVENT_FILE_LOADED: { + if (App.AutoPlay && Paused) + SetPropertyBool("pause", false); + HideLogo(); + Duration = TimeSpan.FromSeconds(GetPropertyDouble("duration")); if (App.StartSize == "video") @@ -1148,12 +1166,7 @@ namespace mpvnet else { if (i == 0 && !append) - { CommandV("loadfile", file); - - if (App.AutoPlay && Paused) - SetPropertyBool("pause", false); - } else CommandV("loadfile", file, "append"); } diff --git a/src/Resources/editor_conf.txt b/src/Resources/editor_conf.txt index 4b41900..c1c8a05 100644 --- a/src/Resources/editor_conf.txt +++ b/src/Resources/editor_conf.txt @@ -542,7 +542,7 @@ name = auto-play file = mpvnet default = no filter = Playback -help = Sets pause=no on file load and selecting from the playlist. (mpv.net specific option) +help = Sets pause=no on file load. (mpv.net specific option) option = yes option = no diff --git a/src/Resources/input.conf.txt b/src/Resources/input.conf.txt index 91ed1a7..805d812 100644 --- a/src/Resources/input.conf.txt +++ b/src/Resources/input.conf.txt @@ -17,9 +17,9 @@ Space script-message mpv.net play-pause #menu: Play/Pause Ctrl+s stop #menu: Stop _ ignore #menu: - Enter cycle fullscreen #menu: Toggle Fullscreen - -F11 script-message mpv.net playlist-add -1; set pause no #menu: Navigate > Previous File -F12 script-message mpv.net playlist-add 1; set pause no #menu: Navigate > Next File + +F11 script-message mpv.net playlist-add -1 #menu: Navigate > Previous File +F12 script-message mpv.net playlist-add 1 #menu: Navigate > Next File _ ignore #menu: Navigate > - Home script-message mpv.net playlist-first #menu: Navigate > First File End script-message mpv.net playlist-last #menu: Navigate > Last File @@ -173,8 +173,8 @@ KP6 script-message mpv.net show-progress KP9 ab-loop 7 script-message mpv.net cycle-audio Sharp script-message mpv.net cycle-audio -Ctrl+F11 script-message mpv.net playlist-add -10; set pause no -Ctrl+F12 script-message mpv.net playlist-add 10; set pause no +Ctrl+F11 script-message mpv.net playlist-add -10 +Ctrl+F12 script-message mpv.net playlist-add 10 8 cycle sub j cycle sub q quit