Fix auto-play not working with user scripts

This commit is contained in:
stax76
2022-05-19 23:17:23 +02:00
parent 229ace708d
commit bc0fc2a29d
6 changed files with 37 additions and 30 deletions

View File

@@ -1,4 +1,5 @@
- Fix auto-play not working with user scripts.
- When input.conf is created on the very first start and a - When input.conf is created on the very first start and a
script-opts folder does not exist, a script-opts folder script-opts folder does not exist, a script-opts folder
is created with defaults for osc and console. is created with defaults for osc and console.

View File

@@ -515,12 +515,7 @@ namespace mpvnet
CommandPaletteItem item = new CommandPaletteItem() CommandPaletteItem item = new CommandPaletteItem()
{ {
Text = file.FileName(), Text = file.FileName(),
Action = () => { Action = () => Core.SetPropertyInt("playlist-pos", index)
Core.SetPropertyInt("playlist-pos", index);
if (App.AutoPlay && Core.Paused)
Core.SetPropertyBool("pause", false);
}
}; };
items.Add(item); items.Add(item);

View File

@@ -45,14 +45,15 @@ namespace mpvnet
{ {
Instance = this; 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.FileLoaded += Core_FileLoaded;
Core.Seek += () => UpdateProgressBar(); Core.Pause += Core_Pause;
Core.PlaylistPosChanged += (value) => SetTitle(); 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") if (Core.GPUAPI != "vulkan")
Init(); Init();
@@ -126,7 +127,6 @@ namespace mpvnet
Core.ObservePropertyBool("fullscreen", PropChangeFullscreen); Core.ObservePropertyBool("fullscreen", PropChangeFullscreen);
Core.ObservePropertyBool("keepaspect-window", value => Core.KeepaspectWindow = value); Core.ObservePropertyBool("keepaspect-window", value => Core.KeepaspectWindow = value);
Core.ObservePropertyBool("ontop", PropChangeOnTop); Core.ObservePropertyBool("ontop", PropChangeOnTop);
Core.ObservePropertyBool("pause", PropChangePause);
Core.ObservePropertyString("sid", PropChangeSid); Core.ObservePropertyString("sid", PropChangeSid);
Core.ObservePropertyString("aid", PropChangeAid); 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 (Taskbar != null && Core.TaskbarProgress)
{ {
if (paused) if (Core.Paused)
Taskbar.SetState(TaskbarStates.Paused); Taskbar.SetState(TaskbarStates.Paused);
else else
Taskbar.SetState(TaskbarStates.Normal); Taskbar.SetState(TaskbarStates.Normal);

View File

@@ -53,6 +53,7 @@ namespace mpvnet
public event Action Initialized; public event Action Initialized;
public event Action InitializedAsync; public event Action InitializedAsync;
public event Action Pause;
public event Action ShowMenu; public event Action ShowMenu;
public event Action<float> ScaleWindow; public event Action<float> ScaleWindow;
public event Action<float> WindowScale; public event Action<float> WindowScale;
@@ -144,6 +145,10 @@ namespace mpvnet
ProcessCommandLine(true); ProcessCommandLine(true);
mpv_error err = mpv_initialize(Handle); mpv_error err = mpv_initialize(Handle);
if (err < 0)
throw new Exception("mpv_initialize error" + BR2 + GetError(err) + BR);
string idle = GetPropertyString("idle"); string idle = GetPropertyString("idle");
App.Exit = idle == "no" || idle == "once"; App.Exit = idle == "no" || idle == "once";
@@ -151,8 +156,10 @@ namespace mpvnet
// this means Lua scripts that use idle might not work correctly // this means Lua scripts that use idle might not work correctly
SetPropertyString("idle", "yes"); SetPropertyString("idle", "yes");
if (err < 0) ObservePropertyBool("pause", value => {
throw new Exception("mpv_initialize error" + BR2 + GetError(err) + BR); Paused = value;
Pause();
});
ObservePropertyInt("video-rotate", value => { ObservePropertyInt("video-rotate", value => {
VideoRotate = 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(); Initialized?.Invoke();
InvokeAsync(InitializedAsync); InvokeAsync(InitializedAsync);
} }
@@ -463,7 +477,11 @@ namespace mpvnet
break; break;
case mpv_event_id.MPV_EVENT_FILE_LOADED: case mpv_event_id.MPV_EVENT_FILE_LOADED:
{ {
if (App.AutoPlay && Paused)
SetPropertyBool("pause", false);
HideLogo(); HideLogo();
Duration = TimeSpan.FromSeconds(GetPropertyDouble("duration")); Duration = TimeSpan.FromSeconds(GetPropertyDouble("duration"));
if (App.StartSize == "video") if (App.StartSize == "video")
@@ -1148,12 +1166,7 @@ namespace mpvnet
else else
{ {
if (i == 0 && !append) if (i == 0 && !append)
{
CommandV("loadfile", file); CommandV("loadfile", file);
if (App.AutoPlay && Paused)
SetPropertyBool("pause", false);
}
else else
CommandV("loadfile", file, "append"); CommandV("loadfile", file, "append");
} }

View File

@@ -542,7 +542,7 @@ name = auto-play
file = mpvnet file = mpvnet
default = no default = no
filter = Playback 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 = yes
option = no option = no

View File

@@ -17,9 +17,9 @@ Space script-message mpv.net play-pause #menu: Play/Pause
Ctrl+s stop #menu: Stop Ctrl+s stop #menu: Stop
_ ignore #menu: - _ ignore #menu: -
Enter cycle fullscreen #menu: Toggle Fullscreen Enter cycle fullscreen #menu: Toggle Fullscreen
F11 script-message mpv.net playlist-add -1; set pause no #menu: Navigate > Previous File F11 script-message mpv.net playlist-add -1 #menu: Navigate > Previous File
F12 script-message mpv.net playlist-add 1; set pause no #menu: Navigate > Next File F12 script-message mpv.net playlist-add 1 #menu: Navigate > Next File
_ ignore #menu: Navigate > - _ ignore #menu: Navigate > -
Home script-message mpv.net playlist-first #menu: Navigate > First File Home script-message mpv.net playlist-first #menu: Navigate > First File
End script-message mpv.net playlist-last #menu: Navigate > Last 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 KP9 ab-loop
7 script-message mpv.net cycle-audio 7 script-message mpv.net cycle-audio
Sharp 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+F11 script-message mpv.net playlist-add -10
Ctrl+F12 script-message mpv.net playlist-add 10; set pause no Ctrl+F12 script-message mpv.net playlist-add 10
8 cycle sub 8 cycle sub
j cycle sub j cycle sub
q quit q quit