Implementation for the mpv title property.

mpv window-scale property works now exactly like in mpv.
This commit is contained in:
Frank Skare
2021-03-10 13:28:39 +01:00
parent a7fe444067
commit 62789fa036
16 changed files with 206 additions and 149 deletions

View File

@@ -1,4 +1,11 @@
5.4.8.8 Beta (2021-03-??)
=========================
- The mpv window-scale property works now exactly like in mpv.
- Implementation for the mpv title property.
5.4.8.7 Beta (2021-03-09) 5.4.8.7 Beta (2021-03-09)
========================= =========================

View File

@@ -10,6 +10,8 @@ $7z = 'C:\Program Files\7-Zip\7z.exe'
$cloudDirectories = 'C:\Users\frank\OneDrive\Public\mpv.net\', $cloudDirectories = 'C:\Users\frank\OneDrive\Public\mpv.net\',
'C:\Users\frank\Dropbox\Public\mpv.net\' 'C:\Users\frank\Dropbox\Public\mpv.net\'
cd $PSScriptRoot
function UploadBeta($sourceFile) function UploadBeta($sourceFile)
{ {
foreach ($cloudDirectory in $cloudDirectories) foreach ($cloudDirectory in $cloudDirectories)

View File

@@ -12,11 +12,6 @@ namespace mpvnet
{ {
public static class App public static class App
{ {
public static string[] VideoTypes { get; set; } = "264 265 asf avc avi avs dav flv h264 h265 hevc m2t m2ts m2v m4v mkv mov mp4 mpeg mpg mpv mts ts vob vpy webm wmv y4m".Split(' ');
public static string[] AudioTypes { get; set; } = "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; set; } = { "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; public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName;
public static string ConfPath { get => core.ConfigFolder + "mpvnet.conf"; } public static string ConfPath { get => core.ConfigFolder + "mpvnet.conf"; }
public static string ProcessInstance { get; set; } = "single"; public static string ProcessInstance { get; set; } = "single";

View File

@@ -1,5 +1,6 @@
 
using System; using System;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@@ -9,7 +10,7 @@ using System.Windows;
using VB = Microsoft.VisualBasic; using VB = Microsoft.VisualBasic;
using static NewLine; using static mpvnet.NewLine;
using static mpvnet.Core; using static mpvnet.Core;
namespace mpvnet namespace mpvnet
@@ -20,36 +21,37 @@ namespace mpvnet
{ {
switch (id) switch (id)
{ {
case "open-files": OpenFiles(args); break; case "add-files-to-playlist": OpenFiles("append"); break; // deprecated 2019
case "update-check": UpdateCheck.CheckOnline(true); break;
case "open-url": OpenURL(); break;
case "open-optical-media": Open_DVD_Or_BD_Folder(); break;
case "manage-file-associations": // deprecated 2019
case "show-setup-dialog": ShowDialog(typeof(SetupWindow)); break;
case "cycle-audio": CycleAudio(); break; case "cycle-audio": CycleAudio(); break;
case "execute-mpv-command": ExecuteMpvCommand(); break;
case "load-audio": LoadAudio(); break; case "load-audio": LoadAudio(); break;
case "load-sub": LoadSubtitle(); break; case "load-sub": LoadSubtitle(); break;
case "execute-mpv-command": ExecuteMpvCommand(); break; case "manage-file-associations": // deprecated 2019
case "show-history": ShowHistory(); break;
case "show-media-search": ShowDialog(typeof(EverythingWindow)); break;
case "show-command-palette": ShowDialog(typeof(CommandPaletteWindow)); break;
case "show-about": ShowDialog(typeof(AboutWindow)); break;
case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break;
case "show-input-editor": ShowDialog(typeof(InputWindow)); break;
case "open-conf-folder": ProcessHelp.ShellExecute(core.ConfigFolder); break; case "open-conf-folder": ProcessHelp.ShellExecute(core.ConfigFolder); break;
case "shell-execute": ProcessHelp.ShellExecute(args[0]); break; case "open-files": OpenFiles(args); break;
case "show-info": ShowInfo(); break; case "open-optical-media": Open_DVD_Or_BD_Folder(); break;
case "open-url": OpenURL(); break;
case "playlist-first": PlaylistFirst(); break; case "playlist-first": PlaylistFirst(); break;
case "playlist-last": PlaylistLast(); break; case "playlist-last": PlaylistLast(); break;
case "scale-window": ScaleWindow(float.Parse(args[0], CultureInfo.InvariantCulture)); break;
case "shell-execute": ProcessHelp.ShellExecute(args[0]); break;
case "show-about": ShowDialog(typeof(AboutWindow)); break;
case "show-audio-devices": ShowTextWithEditor("audio-device-list", core.get_property_osd_string("audio-device-list")); break;
case "show-command-palette": ShowDialog(typeof(CommandPaletteWindow)); break;
case "show-commands": ShowCommands(); break;
case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break;
case "show-decoders": ShowTextWithEditor("decoder-list", mpvHelp.GetDecoders()); break;
case "show-demuxers": ShowTextWithEditor("demuxer-lavf-list", mpvHelp.GetDemuxers()); break;
case "show-history": ShowHistory(); break;
case "show-info": ShowInfo(); break;
case "show-input-editor": ShowDialog(typeof(InputWindow)); break;
case "show-keys": ShowTextWithEditor("input-key-list", core.get_property_string("input-key-list").Replace(",", BR)); break;
case "show-media-search": ShowDialog(typeof(EverythingWindow)); break;
case "show-profiles": ShowTextWithEditor("profile-list", mpvHelp.GetProfiles()); break; case "show-profiles": ShowTextWithEditor("profile-list", mpvHelp.GetProfiles()); break;
case "show-properties": ShowProperties(); break; case "show-properties": ShowProperties(); break;
case "show-commands": ShowCommands(); break;
case "show-keys": ShowTextWithEditor("input-key-list", core.get_property_string("input-key-list").Replace(",", BR)); break;
case "add-files-to-playlist": OpenFiles("append"); break; // deprecated 2019
case "show-audio-devices": ShowTextWithEditor("audio-device-list", core.get_property_osd_string("audio-device-list")); break;
case "show-decoders": ShowTextWithEditor("decoder-list", mpvHelp.GetDecoders()); break;
case "show-protocols": ShowTextWithEditor("protocol-list", mpvHelp.GetProtocols()); break; case "show-protocols": ShowTextWithEditor("protocol-list", mpvHelp.GetProtocols()); break;
case "show-demuxers": ShowTextWithEditor("demuxer-lavf-list", mpvHelp.GetDemuxers()); break; case "show-setup-dialog": ShowDialog(typeof(SetupWindow)); break;
case "update-check": UpdateCheck.CheckOnline(true); break;
default: Msg.ShowError($"No command '{id}' found."); break; default: Msg.ShowError($"No command '{id}' found."); break;
} }
} }
@@ -159,7 +161,7 @@ namespace mpvnet
{ {
fileSize = new FileInfo(path).Length; fileSize = new FileInfo(path).Length;
if (App.AudioTypes.Contains(path.Ext())) if (Core.AudioTypes.Contains(path.Ext()))
{ {
using (MediaInfo mediaInfo = new MediaInfo(path)) using (MediaInfo mediaInfo = new MediaInfo(path))
{ {
@@ -183,7 +185,7 @@ namespace mpvnet
return; return;
} }
} }
else if (App.ImageTypes.Contains(path.Ext())) else if (Core.ImageTypes.Contains(path.Ext()))
{ {
using (MediaInfo mediaInfo = new MediaInfo(path)) using (MediaInfo mediaInfo = new MediaInfo(path))
{ {
@@ -243,7 +245,8 @@ namespace mpvnet
InvokeOnMainThread(new Action(() => { InvokeOnMainThread(new Action(() => {
string clipboard = System.Windows.Forms.Clipboard.GetText(); string clipboard = System.Windows.Forms.Clipboard.GetText();
if (string.IsNullOrEmpty(clipboard) || (!clipboard.Contains("://") && !File.Exists(clipboard)) || clipboard.Contains("\n")) if (string.IsNullOrEmpty(clipboard) || (!clipboard.Contains("://") && !File.Exists(clipboard)) ||
clipboard.Contains("\n"))
{ {
App.ShowError("No URL found", "The clipboard does not contain a valid URL or file."); App.ShowError("No URL found", "The clipboard does not contain a valid URL or file.");
return; return;
@@ -339,9 +342,13 @@ namespace mpvnet
static void ShowTextWithEditor(string name, string text) static void ShowTextWithEditor(string name, string text)
{ {
string file = Path.GetTempPath() + $"\\{name}.txt"; string file = Path.GetTempPath() + $"\\{name}.txt";
//UTF8 without BOM
File.WriteAllText(file, BR + text.Trim() + BR); File.WriteAllText(file, BR + text.Trim() + BR);
ProcessHelp.ShellExecute(file); ProcessHelp.ShellExecute(file);
} }
static void ScaleWindow(float factor)
{
core.RaiseScaleWindow(factor);
}
} }
} }

View File

@@ -5,8 +5,10 @@ using System.Drawing;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using Microsoft.Win32;
using static mpvnet.Core; using static mpvnet.Core;
using static NewLine; using static mpvnet.NewLine;
namespace mpvnet namespace mpvnet
{ {
@@ -18,7 +20,6 @@ namespace mpvnet
{ {
proc.StartInfo.FileName = file; proc.StartInfo.FileName = file;
proc.StartInfo.Arguments = arguments; proc.StartInfo.Arguments = arguments;
// default is true in .NET Framework and false in .NET Core
proc.StartInfo.UseShellExecute = false; proc.StartInfo.UseShellExecute = false;
proc.Start(); proc.Start();
} }
@@ -30,7 +31,6 @@ namespace mpvnet
{ {
proc.StartInfo.FileName = file; proc.StartInfo.FileName = file;
proc.StartInfo.Arguments = arguments; proc.StartInfo.Arguments = arguments;
// default is true in .NET Framework and false in .NET Core
proc.StartInfo.UseShellExecute = true; proc.StartInfo.UseShellExecute = true;
proc.Start(); proc.Start();
} }
@@ -187,4 +187,64 @@ namespace mpvnet
return string.Join(BR, list.Split(',').OrderBy(a => a)); return string.Join(BR, list.Split(',').OrderBy(a => a));
} }
} }
public class RegistryHelp
{
public static string ApplicationKey { get; } = @"HKCU\Software\" + Application.ProductName;
public static void SetValue(string path, string name, object value)
{
using (RegistryKey regKey = GetRootKey(path).CreateSubKey(path.Substring(5), RegistryKeyPermissionCheck.ReadWriteSubTree))
regKey.SetValue(name, value);
}
public static string GetString(string path, string name, string defaultValue = "")
{
object value = GetValue(path, name, defaultValue);
return !(value is string) ? defaultValue : value.ToString();
}
public static int GetInt(string path, string name, int defaultValue = 0)
{
object value = GetValue(path, name, defaultValue);
return !(value is int) ? defaultValue : (int)value;
}
public static object GetValue(string path, string name, object defaultValue = null)
{
using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5)))
return regKey == null ? null : regKey.GetValue(name, defaultValue);
}
public static void RemoveKey(string path)
{
try
{
GetRootKey(path).DeleteSubKeyTree(path.Substring(5), false);
}
catch { }
}
public static void RemoveValue(string path, string name)
{
try
{
using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5), true))
if (regKey != null)
regKey.DeleteValue(name, false);
}
catch { }
}
static RegistryKey GetRootKey(string path)
{
switch (path.Substring(0, 4))
{
case "HKLM": return Registry.LocalMachine;
case "HKCU": return Registry.CurrentUser;
case "HKCR": return Registry.ClassesRoot;
default: throw new Exception();
}
}
}
} }

View File

@@ -1,4 +1,5 @@
 
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@@ -16,6 +17,12 @@ using static mpvnet.Core;
namespace mpvnet namespace mpvnet
{ {
public static class NewLine
{
public static string BR = Environment.NewLine;
public static string BR2 = Environment.NewLine + Environment.NewLine;
}
public class Sys public class Sys
{ {
public static bool IsDarkTheme { public static bool IsDarkTheme {
@@ -67,13 +74,13 @@ namespace mpvnet
RegistryHelp.SetValue($@"HKCR\" + "." + ext, null, ExeFilenameNoExt + "." + ext); RegistryHelp.SetValue($@"HKCR\" + "." + ext, null, ExeFilenameNoExt + "." + ext);
RegistryHelp.SetValue($@"HKCR\" + "." + ext + @"\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, ""); RegistryHelp.SetValue($@"HKCR\" + "." + ext + @"\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, "");
if (App.VideoTypes.Contains(ext)) if (Core.VideoTypes.Contains(ext))
RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "video"); RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "video");
if (App.AudioTypes.Contains(ext)) if (Core.AudioTypes.Contains(ext))
RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "audio"); RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "audio");
if (App.ImageTypes.Contains(ext)) if (Core.ImageTypes.Contains(ext))
RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "image"); RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "image");
RegistryHelp.SetValue($@"HKCR\" + ExeFilenameNoExt + "." + ext + @"\shell\open\command", null, $"\"{ExePath}\" \"%1\""); RegistryHelp.SetValue($@"HKCR\" + ExeFilenameNoExt + "." + ext + @"\shell\open\command", null, $"\"{ExePath}\" \"%1\"");

View File

@@ -1,8 +0,0 @@

using System;
public static class NewLine
{
public static string BR = Environment.NewLine;
public static string BR2 = Environment.NewLine + Environment.NewLine;
}

View File

@@ -7,7 +7,7 @@ using System.Management.Automation.Runspaces;
using System.Threading; using System.Threading;
using static mpvnet.Core; using static mpvnet.Core;
using static NewLine; using static mpvnet.NewLine;
namespace mpvnet namespace mpvnet
{ {

View File

@@ -31,11 +31,11 @@ namespace mpvnet
if (args.Length >= 2 && args[0] == "--reg-file-assoc") if (args.Length >= 2 && args[0] == "--reg-file-assoc")
{ {
if (args[1] == "audio") if (args[1] == "audio")
FileAssociation.Register(App.AudioTypes); FileAssociation.Register(Core.AudioTypes);
else if (args[1] == "video") else if (args[1] == "video")
FileAssociation.Register(App.VideoTypes); FileAssociation.Register(Core.VideoTypes);
else if (args[1] == "image") else if (args[1] == "image")
FileAssociation.Register(App.ImageTypes); FileAssociation.Register(Core.ImageTypes);
else else
FileAssociation.Register(args.Skip(1).ToArray()); FileAssociation.Register(args.Skip(1).ToArray());

View File

@@ -1,64 +0,0 @@

using System;
using Microsoft.Win32;
using System.Windows.Forms;
public class RegistryHelp
{
public static string ApplicationKey { get; } = @"HKCU\Software\" + Application.ProductName;
public static void SetValue(string path, string name, object value)
{
using (RegistryKey regKey = GetRootKey(path).CreateSubKey(path.Substring(5), RegistryKeyPermissionCheck.ReadWriteSubTree))
regKey.SetValue(name, value);
}
public static string GetString(string path, string name, string defaultValue = "")
{
object value = GetValue(path, name, defaultValue);
return !(value is string) ? defaultValue : value.ToString();
}
public static int GetInt(string path, string name, int defaultValue = 0)
{
object value = GetValue(path, name, defaultValue);
return !(value is int) ? defaultValue : (int)value;
}
public static object GetValue(string path, string name, object defaultValue = null)
{
using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5)))
return regKey == null ? null : regKey.GetValue(name, defaultValue);
}
public static void RemoveKey(string path)
{
try
{
GetRootKey(path).DeleteSubKeyTree(path.Substring(5), false);
}
catch { }
}
public static void RemoveValue(string path, string name)
{
try
{
using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5), true))
if (regKey != null)
regKey.DeleteValue(name, false);
}
catch { }
}
static RegistryKey GetRootKey(string path)
{
switch (path.Substring(0, 4))
{
case "HKLM": return Registry.LocalMachine;
case "HKCU": return Registry.CurrentUser;
case "HKCR": return Registry.ClassesRoot;
default: throw new Exception();
}
}
}

View File

@@ -141,8 +141,11 @@
Ctrl+t set ontop yes #menu: View > On Top > Enable Ctrl+t set ontop yes #menu: View > On Top > Enable
Ctrl+T set ontop no #menu: View > On Top > Disable Ctrl+T set ontop no #menu: View > On Top > Disable
Alt++ no-osd set window-scale 1.2 #menu: View > Window Size > Enlarge Alt++ script-message mpv.net scale-window 1.2 #menu: View > Window Size > Enlarge
Alt+- no-osd set window-scale 0.8 #menu: View > Window Size > Shrink Alt+- script-message mpv.net scale-window 0.8 #menu: View > Window Size > Shrink
Alt+0 set window-scale 0.5 #menu: View > Zoom > 50 %
Alt+1 set window-scale 1.0 #menu: View > Zoom > 100 %
Alt+2 set window-scale 2.0 #menu: View > Zoom > 200 %
b cycle border #menu: View > Toggle Border b cycle border #menu: View > Toggle Border
i script-message mpv.net show-info #menu: View > File/Stream Info i script-message mpv.net show-info #menu: View > File/Stream Info
t script-binding stats/display-stats #menu: View > Show Statistics t script-binding stats/display-stats #menu: View > Show Statistics

View File

@@ -142,7 +142,7 @@ namespace mpvnet
Everything_GetResultFullPathName(i, sb, (uint)sb.Capacity); Everything_GetResultFullPathName(i, sb, (uint)sb.Capacity);
string ext = sb.ToString().Ext(); string ext = sb.ToString().Ext();
if (App.AudioTypes.Contains(ext) || App.VideoTypes.Contains(ext) || App.ImageTypes.Contains(ext)) if (Core.AudioTypes.Contains(ext) || Core.VideoTypes.Contains(ext) || Core.ImageTypes.Contains(ext))
items.Add(sb.ToString()); items.Add(sb.ToString());
if (items.Count > 100) if (items.Count > 100)

View File

@@ -50,9 +50,9 @@ namespace mpvnet
} catch {} } catch {}
} }
void AddVideo_Click(object sender, RoutedEventArgs e) => RegFileAssoc(App.VideoTypes); void AddVideo_Click(object sender, RoutedEventArgs e) => RegFileAssoc(Core.VideoTypes);
void AddAudio_Click(object sender, RoutedEventArgs e) => RegFileAssoc(App.AudioTypes); void AddAudio_Click(object sender, RoutedEventArgs e) => RegFileAssoc(Core.AudioTypes);
void AddImage_Click(object sender, RoutedEventArgs e) => RegFileAssoc(App.ImageTypes); void AddImage_Click(object sender, RoutedEventArgs e) => RegFileAssoc(Core.ImageTypes);
void RemoveFileAssociations_Click(object sender, RoutedEventArgs e) void RemoveFileAssociations_Click(object sender, RoutedEventArgs e)
{ {

View File

@@ -49,6 +49,10 @@ namespace mpvnet
Hwnd = Handle; Hwnd = Handle;
ConsoleHelp.Padding = 60; ConsoleHelp.Padding = 60;
core.Init(); core.Init();
core.Title = core.get_property_string("title");
if (core.Title != null && core.Title.EndsWith("} - mpv"))
core.Title = "";
if (App.GlobalMediaKeys) if (App.GlobalMediaKeys)
{ {
@@ -60,6 +64,7 @@ namespace mpvnet
core.Shutdown += Shutdown; core.Shutdown += Shutdown;
core.VideoSizeChanged += VideoSizeChanged; core.VideoSizeChanged += VideoSizeChanged;
core.ScaleWindow += ScaleWindow;
core.FileLoaded += FileLoaded; core.FileLoaded += FileLoaded;
core.Idle += Idle; core.Idle += Idle;
core.Seek += () => UpdateProgressBar(); core.Seek += () => UpdateProgressBar();
@@ -75,6 +80,8 @@ namespace mpvnet
core.observe_property_string("aid", PropChangeAid); core.observe_property_string("aid", PropChangeAid);
core.observe_property_string("vid", PropChangeVid); core.observe_property_string("vid", PropChangeVid);
core.observe_property_string("title", PropChangeTitle);
core.observe_property_int("edition", PropChangeEdition); core.observe_property_int("edition", PropChangeEdition);
core.observe_property_double("window-scale", PropChangeWindowScale); core.observe_property_double("window-scale", PropChangeWindowScale);
@@ -84,7 +91,8 @@ namespace mpvnet
AppDomain.CurrentDomain.UnhandledException += (sender, e) => App.ShowException(e.ExceptionObject); AppDomain.CurrentDomain.UnhandledException += (sender, e) => App.ShowException(e.ExceptionObject);
Application.ThreadException += (sender, e) => App.ShowException(e.Exception); Application.ThreadException += (sender, e) => App.ShowException(e.Exception);
Msg.SupportURL = "https://github.com/stax76/mpv.net#support"; Msg.SupportURL = "https://github.com/stax76/mpv.net#support";
Text = "mpv.net " + Application.ProductVersion;
Text = string.IsNullOrEmpty(core.Title) ? "mpv.net " + Application.ProductVersion : core.Title;
TaskbarButtonCreatedMessage = RegisterWindowMessage("TaskbarButtonCreated"); TaskbarButtonCreatedMessage = RegisterWindowMessage("TaskbarButtonCreated");
ContextMenu = new ContextMenuStripEx(components); ContextMenu = new ContextMenuStripEx(components);
@@ -138,13 +146,27 @@ namespace mpvnet
} }
} }
void ScaleWindow(float value)
{
BeginInvoke(new Action(() => SetFormPosAndSize(value)));
}
void WindowScale(double scale)
{
if (!WasShown())
return;
Size size = new Size((int)(core.VideoSize.Width * scale), (int)(core.VideoSize.Height * scale));
SetSize(size, core.VideoSize, Screen.FromControl(this), false, false);
}
public MenuItem FindMenuItem(string text) => FindMenuItem(text, ContextMenu.Items); public MenuItem FindMenuItem(string text) => FindMenuItem(text, ContextMenu.Items);
void Shutdown() => BeginInvoke(new Action(() => Close())); void Shutdown() => BeginInvoke(new Action(() => Close()));
void Idle() void Idle()
{ {
BeginInvoke(new Action(() => Text = "mpv.net " + Application.ProductVersion)); BeginInvoke(new Action(() => Text = string.IsNullOrEmpty(core.Title) ? "mpv.net " + Application.ProductVersion : core.Title));
} }
bool WasShown() => ShownTickCount != 0 && Environment.TickCount > ShownTickCount + 500; bool WasShown() => ShownTickCount != 0 && Environment.TickCount > ShownTickCount + 500;
@@ -353,19 +375,31 @@ namespace mpvnet
} }
height = Convert.ToInt32(height * scale); height = Convert.ToInt32(height * scale);
int width = height * videoSize.Width / videoSize.Height; SetSize(new Size(height * videoSize.Width / videoSize.Height, height), videoSize, screen);
}
void SetSize(Size size,
Size videoSize,
Screen screen,
bool checkAutofitSmaller = true,
bool checkAutofitLarger = true)
{
int height = size.Height;
int width = size.Height * videoSize.Width / videoSize.Height;
int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height); int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height);
int maxWidth = screen.WorkingArea.Width - (Width - ClientSize.Width); int maxWidth = screen.WorkingArea.Width - (Width - ClientSize.Width);
if (height < maxHeight * core.AutofitSmaller) if (checkAutofitSmaller && (height < maxHeight * core.AutofitSmaller))
{ {
height = Convert.ToInt32(maxHeight * core.AutofitSmaller); height = Convert.ToInt32(maxHeight * core.AutofitSmaller);
width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); width = Convert.ToInt32(height * videoSize.Width / videoSize.Height);
} }
if (height > maxHeight * core.AutofitLarger) float autofitLarger = checkAutofitLarger ? core.AutofitLarger : 1;
if (height > maxHeight * autofitLarger)
{ {
height = Convert.ToInt32(maxHeight * core.AutofitLarger); height = Convert.ToInt32(maxHeight * autofitLarger);
width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); width = Convert.ToInt32(height * videoSize.Width / videoSize.Height);
} }
@@ -399,8 +433,7 @@ namespace mpvnet
if (top + rect.Height > maxBottom) if (top + rect.Height > maxBottom)
top = maxBottom - rect.Height; top = maxBottom - rect.Height;
SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, SetWindowPos(Handle, IntPtr.Zero, left, top, rect.Width, rect.Height, 4);
left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */);
} }
public void CycleFullscreen(bool enabled) public void CycleFullscreen(bool enabled)
@@ -484,10 +517,15 @@ namespace mpvnet
string path = core.get_property_string("path"); string path = core.get_property_string("path");
BeginInvoke(new Action(() => { BeginInvoke(new Action(() => {
if (string.IsNullOrEmpty(core.Title))
{
if (path.Contains("://")) if (path.Contains("://"))
Text = core.get_property_string("media-title") + " - mpv.net " + Application.ProductVersion; Text = core.get_property_string("media-title") + " - mpv.net " + Application.ProductVersion;
else else
Text = path.FileName() + " - mpv.net " + Application.ProductVersion; Text = path.FileName() + " - mpv.net " + Application.ProductVersion;
}
else
Text = core.Title;
int interval = (int)(core.Duration.TotalMilliseconds / 100); int interval = (int)(core.Duration.TotalMilliseconds / 100);
@@ -705,16 +743,14 @@ namespace mpvnet
void PropChangeVid(string value) => core.Vid = value; void PropChangeVid(string value) => core.Vid = value;
void PropChangeTitle(string value) => BeginInvoke(new Action(() => {
if (value != null && !value.EndsWith("} - mpv"))
Text = value;
}));
void PropChangeEdition(int value) => core.Edition = value; void PropChangeEdition(int value) => core.Edition = value;
void PropChangeWindowScale(double value) void PropChangeWindowScale(double value) => BeginInvoke(new Action(() => WindowScale(value)));
{
if (value != 1)
{
BeginInvoke(new Action(() => SetFormPosAndSize(value)));
core.command("no-osd set window-scale 1");
}
}
void PropChangeWindowMaximized() void PropChangeWindowMaximized()
{ {

View File

@@ -95,7 +95,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Misc\App.cs" /> <Compile Include="Misc\App.cs" />
<Compile Include="Misc\NewLine.cs" />
<Compile Include="Misc\Extension.cs" /> <Compile Include="Misc\Extension.cs" />
<Content Include="..\License.txt"> <Content Include="..\License.txt">
<Link>License.txt</Link> <Link>License.txt</Link>
@@ -129,7 +128,6 @@
</Page> </Page>
<Compile Include="Misc\Help.cs" /> <Compile Include="Misc\Help.cs" />
<Compile Include="Misc\UpdateCheck.cs" /> <Compile Include="Misc\UpdateCheck.cs" />
<Compile Include="Misc\RegistryHelp.cs" />
<Compile Include="Misc\Theme.cs" /> <Compile Include="Misc\Theme.cs" />
<Compile Include="Misc\PowerShell.cs" /> <Compile Include="Misc\PowerShell.cs" />
<Compile Include="Native\StockIcon.cs" /> <Compile Include="Native\StockIcon.cs" />

View File

@@ -11,7 +11,7 @@ using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using static libmpv; using static libmpv;
using static NewLine; using static mpvnet.NewLine;
using System.Globalization; using System.Globalization;
@@ -20,6 +20,12 @@ namespace mpvnet
public class Core public class Core
{ {
public static Core core { get; } = new Core(); public static Core core { get; } = new Core();
public static Core GetCore() => core;
public static string[] VideoTypes { get; set; } = "264 265 asf avc avi avs dav flv h264 h265 hevc m2t m2ts m2v m4v mkv mov mp4 mpeg mpg mpv mts ts vob vpy webm wmv y4m".Split(' ');
public static string[] AudioTypes { get; set; } = "aac ac3 dts dtshd dtshr dtsma eac3 flac m4a mka mp2 mp3 mpa mpc ogg opus thd thd+ac3 w64 wav".Split(' ');
public static string[] ImageTypes { get; set; } = { "jpg", "bmp", "png", "gif" };
public static string[] SubtitleTypes { get; } = { "srt", "ass", "idx", "sup", "ttxt", "ssa", "smi" };
public event Action<mpv_log_level, string> LogMessageAsync; // log-message MPV_EVENT_LOG_MESSAGE public event Action<mpv_log_level, string> LogMessageAsync; // log-message MPV_EVENT_LOG_MESSAGE
public event Action<mpv_end_file_reason> EndFileAsync; // end-file MPV_EVENT_END_FILE public event Action<mpv_end_file_reason> EndFileAsync; // end-file MPV_EVENT_END_FILE
@@ -69,6 +75,7 @@ namespace mpvnet
public event Action VideoSizeChanged; public event Action VideoSizeChanged;
public event Action VideoSizeChangedAsync; public event Action VideoSizeChangedAsync;
public event Action<float> ScaleWindow;
public Dictionary<string, List<Action>> PropChangeActions { get; set; } = new Dictionary<string, List<Action>>(); public Dictionary<string, List<Action>> PropChangeActions { get; set; } = new Dictionary<string, List<Action>>();
public Dictionary<string, List<Action<int>>> IntPropChangeActions { get; set; } = new Dictionary<string, List<Action<int>>>(); public Dictionary<string, List<Action<int>>> IntPropChangeActions { get; set; } = new Dictionary<string, List<Action<int>>>();
@@ -88,12 +95,13 @@ namespace mpvnet
public AutoResetEvent ShutdownAutoResetEvent { get; } = new AutoResetEvent(false); public AutoResetEvent ShutdownAutoResetEvent { get; } = new AutoResetEvent(false);
public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false); public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false);
public string InputConfPath { get => ConfigFolder + "input.conf"; }
public string ConfPath { get => ConfigFolder + "mpv.conf"; }
public string Sid { get; set; } = "";
public string Aid { get; set; } = ""; public string Aid { get; set; } = "";
public string Vid { get; set; } = ""; public string ConfPath { get => ConfigFolder + "mpv.conf"; }
public string GPUAPI { get; set; } = "auto"; public string GPUAPI { get; set; } = "auto";
public string InputConfPath { get => ConfigFolder + "input.conf"; }
public string Sid { get; set; } = "";
public string Title { get; set; } = "";
public string Vid { get; set; } = "";
public bool WasInitialSizeSet; public bool WasInitialSizeSet;
public bool Border { get; set; } = true; public bool Border { get; set; } = true;
@@ -172,6 +180,7 @@ namespace mpvnet
case "taskbar-progress": TaskbarProgress = value == "yes"; break; case "taskbar-progress": TaskbarProgress = value == "yes"; break;
case "screen": Screen = Convert.ToInt32(value); break; case "screen": Screen = Convert.ToInt32(value); break;
case "gpu-api": GPUAPI = value; break; case "gpu-api": GPUAPI = value; break;
case "title": Title = value; break;
} }
if (AutofitLarger > 1) if (AutofitLarger > 1)
@@ -1077,7 +1086,7 @@ namespace mpvnet
if (file.Ext() == "iso") if (file.Ext() == "iso")
LoadISO(file); LoadISO(file);
else if(App.SubtitleTypes.Contains(file.Ext())) else if(Core.SubtitleTypes.Contains(file.Ext()))
commandv("sub-add", file); commandv("sub-add", file);
else if (file.Ext().Length != 3 && File.Exists(Path.Combine(file, "BDMV\\index.bdmv"))) else if (file.Ext().Length != 3 && File.Exists(Path.Combine(file, "BDMV\\index.bdmv")))
{ {
@@ -1157,9 +1166,9 @@ namespace mpvnet
List<string> files = Directory.GetFiles(dir).ToList(); List<string> files = Directory.GetFiles(dir).ToList();
files = files.Where(file => files = files.Where(file =>
App.VideoTypes.Contains(file.Ext()) || Core.VideoTypes.Contains(file.Ext()) ||
App.AudioTypes.Contains(file.Ext()) || Core.AudioTypes.Contains(file.Ext()) ||
App.ImageTypes.Contains(file.Ext())).ToList(); Core.ImageTypes.Contains(file.Ext())).ToList();
files.Sort(new StringLogicalComparer()); files.Sort(new StringLogicalComparer());
int index = files.IndexOf(path); int index = files.IndexOf(path);
@@ -1265,6 +1274,11 @@ namespace mpvnet
return id; return id;
} }
public void RaiseScaleWindow(float value)
{
ScaleWindow(value);
}
void ReadMetaData() void ReadMetaData()
{ {
string path = get_property_string("path"); string path = get_property_string("path");