global media keys
This commit is contained in:
@@ -14,7 +14,7 @@ namespace mpvnet
|
||||
{
|
||||
public static string[] VideoTypes { get; } = "264 265 asf avc avi avs flv h264 h265 hevc m2ts m2v m4v mkv mov mp4 mpeg mpg mpv mts ts vob vpy webm wmv y4m".Split(' ');
|
||||
public static string[] AudioTypes { get; } = "mp3 mp2 ac3 ogg opus flac wav w64 m4a dts dtsma dtshr dtshd eac3 thd thd+ac3 mka aac mpa".Split(' ');
|
||||
public static string[] ImageTypes { get; } = {"jpg", "bmp", "gif", "png"};
|
||||
public static string[] ImageTypes { get; } = { "jpg", "bmp", "gif", "png" };
|
||||
public static string[] SubtitleTypes { get; } = { "srt", "ass", "idx", "sup", "ttxt", "ssa", "smi" };
|
||||
|
||||
public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName;
|
||||
@@ -32,6 +32,7 @@ namespace mpvnet
|
||||
public static bool AutoLoadFolder { get; set; } = true;
|
||||
public static bool Queue { get; set; }
|
||||
public static bool UpdateCheck { get; set; }
|
||||
public static bool GlobalMediaKeys { get; set; }
|
||||
|
||||
public static int StartThreshold { get; set; } = 1500;
|
||||
public static int RecentCount { get; set; } = 15;
|
||||
@@ -52,7 +53,7 @@ namespace mpvnet
|
||||
foreach (var i in Conf)
|
||||
ProcessProperty(i.Key, i.Value, true);
|
||||
|
||||
if (App.DebugMode)
|
||||
if (DebugMode)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -106,14 +107,14 @@ namespace mpvnet
|
||||
{
|
||||
if (obj is Exception e)
|
||||
{
|
||||
if (App.IsStartedFromTerminal)
|
||||
if (IsStartedFromTerminal)
|
||||
ConsoleHelp.WriteError(e.ToString());
|
||||
else
|
||||
Msg.ShowException(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (App.IsStartedFromTerminal)
|
||||
if (IsStartedFromTerminal)
|
||||
ConsoleHelp.WriteError(obj.ToString());
|
||||
else
|
||||
Msg.ShowError(obj.ToString());
|
||||
@@ -122,7 +123,7 @@ namespace mpvnet
|
||||
|
||||
public static void ShowError(string title, string msg)
|
||||
{
|
||||
if (App.IsStartedFromTerminal)
|
||||
if (IsStartedFromTerminal)
|
||||
{
|
||||
ConsoleHelp.WriteError(title);
|
||||
ConsoleHelp.WriteError(msg);
|
||||
@@ -135,8 +136,8 @@ namespace mpvnet
|
||||
{
|
||||
if (RememberVolume)
|
||||
{
|
||||
core.set_property_int("volume", RegistryHelp.GetInt(App.RegPath, "Volume", 70));
|
||||
core.set_property_string("mute", RegistryHelp.GetString(App.RegPath, "Mute", "no"));
|
||||
core.set_property_int("volume", RegistryHelp.GetInt(RegPath, "Volume", 70));
|
||||
core.set_property_string("mute", RegistryHelp.GetString(RegPath, "Mute", "no"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,8 +145,8 @@ namespace mpvnet
|
||||
{
|
||||
if (RememberVolume)
|
||||
{
|
||||
RegistryHelp.SetValue(App.RegPath, "Volume", core.get_property_int("volume"));
|
||||
RegistryHelp.SetValue(App.RegPath, "Mute", core.get_property_string("mute"));
|
||||
RegistryHelp.SetValue(RegPath, "Volume", core.get_property_int("volume"));
|
||||
RegistryHelp.SetValue(RegPath, "Mute", core.get_property_string("mute"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +171,7 @@ namespace mpvnet
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "global-media-keys": GlobalMediaKeys = value == "yes"; return true;
|
||||
case "remember-position": RememberPosition = value == "yes"; return true;
|
||||
case "debug-mode": DebugMode = value == "yes"; return true;
|
||||
case "remember-volume": RememberVolume = value == "yes"; return true;
|
||||
|
||||
@@ -5,6 +5,11 @@ using System.Runtime.InteropServices;
|
||||
|
||||
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")]
|
||||
public static extern bool AttachConsole(int dwProcessId);
|
||||
|
||||
@@ -14,8 +19,12 @@ public class WinAPI
|
||||
[DllImport("kernel32.dll")]
|
||||
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)]
|
||||
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)]
|
||||
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" },
|
||||
{ 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]]
|
||||
name = "input-ar-delay"
|
||||
file = "mpv"
|
||||
|
||||
@@ -49,6 +49,9 @@ namespace mpvnet
|
||||
ConsoleHelp.Padding = 60;
|
||||
core.Init();
|
||||
|
||||
if (App.GlobalMediaKeys)
|
||||
RegisterGlobalMediaKeys();
|
||||
|
||||
core.Shutdown += Shutdown;
|
||||
core.VideoSizeChanged += VideoSizeChanged;
|
||||
core.FileLoaded += FileLoaded;
|
||||
@@ -562,6 +565,23 @@ namespace mpvnet
|
||||
}
|
||||
}
|
||||
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
|
||||
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)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
|
||||
Reference in New Issue
Block a user