global media keys
This commit is contained in:
@@ -32,6 +32,7 @@ namespace mpvnet
|
|||||||
public static bool AutoLoadFolder { get; set; } = true;
|
public static bool AutoLoadFolder { get; set; } = true;
|
||||||
public static bool Queue { get; set; }
|
public static bool Queue { get; set; }
|
||||||
public static bool UpdateCheck { get; set; }
|
public static bool UpdateCheck { get; set; }
|
||||||
|
public static bool GlobalMediaKeys { get; set; }
|
||||||
|
|
||||||
public static int StartThreshold { get; set; } = 1500;
|
public static int StartThreshold { get; set; } = 1500;
|
||||||
public static int RecentCount { get; set; } = 15;
|
public static int RecentCount { get; set; } = 15;
|
||||||
@@ -52,7 +53,7 @@ namespace mpvnet
|
|||||||
foreach (var i in Conf)
|
foreach (var i in Conf)
|
||||||
ProcessProperty(i.Key, i.Value, true);
|
ProcessProperty(i.Key, i.Value, true);
|
||||||
|
|
||||||
if (App.DebugMode)
|
if (DebugMode)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -106,14 +107,14 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
if (obj is Exception e)
|
if (obj is Exception e)
|
||||||
{
|
{
|
||||||
if (App.IsStartedFromTerminal)
|
if (IsStartedFromTerminal)
|
||||||
ConsoleHelp.WriteError(e.ToString());
|
ConsoleHelp.WriteError(e.ToString());
|
||||||
else
|
else
|
||||||
Msg.ShowException(e);
|
Msg.ShowException(e);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (App.IsStartedFromTerminal)
|
if (IsStartedFromTerminal)
|
||||||
ConsoleHelp.WriteError(obj.ToString());
|
ConsoleHelp.WriteError(obj.ToString());
|
||||||
else
|
else
|
||||||
Msg.ShowError(obj.ToString());
|
Msg.ShowError(obj.ToString());
|
||||||
@@ -122,7 +123,7 @@ namespace mpvnet
|
|||||||
|
|
||||||
public static void ShowError(string title, string msg)
|
public static void ShowError(string title, string msg)
|
||||||
{
|
{
|
||||||
if (App.IsStartedFromTerminal)
|
if (IsStartedFromTerminal)
|
||||||
{
|
{
|
||||||
ConsoleHelp.WriteError(title);
|
ConsoleHelp.WriteError(title);
|
||||||
ConsoleHelp.WriteError(msg);
|
ConsoleHelp.WriteError(msg);
|
||||||
@@ -135,8 +136,8 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
if (RememberVolume)
|
if (RememberVolume)
|
||||||
{
|
{
|
||||||
core.set_property_int("volume", RegistryHelp.GetInt(App.RegPath, "Volume", 70));
|
core.set_property_int("volume", RegistryHelp.GetInt(RegPath, "Volume", 70));
|
||||||
core.set_property_string("mute", RegistryHelp.GetString(App.RegPath, "Mute", "no"));
|
core.set_property_string("mute", RegistryHelp.GetString(RegPath, "Mute", "no"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,8 +145,8 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
if (RememberVolume)
|
if (RememberVolume)
|
||||||
{
|
{
|
||||||
RegistryHelp.SetValue(App.RegPath, "Volume", core.get_property_int("volume"));
|
RegistryHelp.SetValue(RegPath, "Volume", core.get_property_int("volume"));
|
||||||
RegistryHelp.SetValue(App.RegPath, "Mute", core.get_property_string("mute"));
|
RegistryHelp.SetValue(RegPath, "Mute", core.get_property_string("mute"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,6 +171,7 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
|
case "global-media-keys": GlobalMediaKeys = value == "yes"; return true;
|
||||||
case "remember-position": RememberPosition = value == "yes"; return true;
|
case "remember-position": RememberPosition = value == "yes"; return true;
|
||||||
case "debug-mode": DebugMode = value == "yes"; return true;
|
case "debug-mode": DebugMode = value == "yes"; return true;
|
||||||
case "remember-volume": RememberVolume = value == "yes"; return true;
|
case "remember-volume": RememberVolume = value == "yes"; return true;
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
public class WinAPI
|
public class WinAPI
|
||||||
{
|
{
|
||||||
|
public const int VK_MEDIA_NEXT_TRACK = 0xB0;
|
||||||
|
public const int VK_MEDIA_PREV_TRACK = 0xB1;
|
||||||
|
public const int VK_MEDIA_STOP = 0xB2;
|
||||||
|
public const int VK_MEDIA_PLAY_PAUSE = 0xB3;
|
||||||
|
|
||||||
[DllImport("kernel32.dll")]
|
[DllImport("kernel32.dll")]
|
||||||
public static extern bool AttachConsole(int dwProcessId);
|
public static extern bool AttachConsole(int dwProcessId);
|
||||||
|
|
||||||
@@ -14,8 +19,12 @@ public class WinAPI
|
|||||||
[DllImport("kernel32.dll")]
|
[DllImport("kernel32.dll")]
|
||||||
public static extern IntPtr LoadLibrary(string path);
|
public static extern IntPtr LoadLibrary(string path);
|
||||||
|
|
||||||
|
[DllImport("user32")]
|
||||||
|
public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
||||||
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
|
public static extern IntPtr FindWindowEx(
|
||||||
|
IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
||||||
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|||||||
@@ -516,6 +516,15 @@ help = "For single files automatically load the entire directory into the playli
|
|||||||
options = [{ name = "yes" },
|
options = [{ name = "yes" },
|
||||||
{ name = "no" }]
|
{ name = "no" }]
|
||||||
|
|
||||||
|
[[settings]]
|
||||||
|
name = "global-media-keys"
|
||||||
|
file = "mpvnet"
|
||||||
|
default = "no"
|
||||||
|
filter = "Input"
|
||||||
|
help = "Enable global media keys next track, previous track, play/pause, stop. (mpv.net specific setting)"
|
||||||
|
options = [{ name = "yes" },
|
||||||
|
{ name = "no" }]
|
||||||
|
|
||||||
[[settings]]
|
[[settings]]
|
||||||
name = "input-ar-delay"
|
name = "input-ar-delay"
|
||||||
file = "mpv"
|
file = "mpv"
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ namespace mpvnet
|
|||||||
ConsoleHelp.Padding = 60;
|
ConsoleHelp.Padding = 60;
|
||||||
core.Init();
|
core.Init();
|
||||||
|
|
||||||
|
if (App.GlobalMediaKeys)
|
||||||
|
RegisterGlobalMediaKeys();
|
||||||
|
|
||||||
core.Shutdown += Shutdown;
|
core.Shutdown += Shutdown;
|
||||||
core.VideoSizeChanged += VideoSizeChanged;
|
core.VideoSizeChanged += VideoSizeChanged;
|
||||||
core.FileLoaded += FileLoaded;
|
core.FileLoaded += FileLoaded;
|
||||||
@@ -562,6 +565,23 @@ namespace mpvnet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 0x0312: // WM_HOTKEY
|
||||||
|
switch (m.WParam.ToInt64())
|
||||||
|
{
|
||||||
|
case WinAPI.VK_MEDIA_NEXT_TRACK:
|
||||||
|
core.command("keypress NEXT");
|
||||||
|
break;
|
||||||
|
case WinAPI.VK_MEDIA_PREV_TRACK:
|
||||||
|
core.command("keypress PREV");
|
||||||
|
break;
|
||||||
|
case WinAPI.VK_MEDIA_PLAY_PAUSE:
|
||||||
|
core.command("keypress PLAYPAUSE");
|
||||||
|
break;
|
||||||
|
case WinAPI.VK_MEDIA_STOP:
|
||||||
|
core.command("keypress STOP");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 0x0200: // WM_MOUSEMOVE
|
case 0x0200: // WM_MOUSEMOVE
|
||||||
if (Environment.TickCount - LastCycleFullscreen > 500)
|
if (Environment.TickCount - LastCycleFullscreen > 500)
|
||||||
{
|
{
|
||||||
@@ -750,6 +770,14 @@ namespace mpvnet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RegisterGlobalMediaKeys()
|
||||||
|
{
|
||||||
|
WinAPI.RegisterHotKey(Handle, WinAPI.VK_MEDIA_NEXT_TRACK, 0, (uint)WinAPI.VK_MEDIA_NEXT_TRACK);
|
||||||
|
WinAPI.RegisterHotKey(Handle, WinAPI.VK_MEDIA_PREV_TRACK, 0, (uint)WinAPI.VK_MEDIA_PREV_TRACK);
|
||||||
|
WinAPI.RegisterHotKey(Handle, WinAPI.VK_MEDIA_PLAY_PAUSE, 0, (uint)WinAPI.VK_MEDIA_PLAY_PAUSE);
|
||||||
|
WinAPI.RegisterHotKey(Handle, WinAPI.VK_MEDIA_STOP, 0, (uint)WinAPI.VK_MEDIA_STOP);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnLoad(EventArgs e)
|
protected override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnLoad(e);
|
base.OnLoad(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user