proper mpv title property implementation

This commit is contained in:
Frank Skare
2021-04-30 14:53:41 +02:00
parent 6e2d11952f
commit 0343b32847
4 changed files with 35 additions and 37 deletions

View File

@@ -8,7 +8,7 @@
- The code from the included JavaScript file was ported into the core player - The code from the included JavaScript file was ported into the core player
because JavaScript is currently broken in the builds of shinshiro. because JavaScript is currently broken in the builds of shinshiro.
- MediaInfo 21.3 - MediaInfo 21.3
- libmpv 2021-02-28 - libmpv shinchiro 2021-04-04
5.4.8.7 Beta (2021-03-09) 5.4.8.7 Beta (2021-03-09)

View File

@@ -492,17 +492,13 @@ The documentation of mpvs window features can be found here:
mpv.net has currently implemented the following window features: mpv.net has currently implemented the following window features:
[screen](https://mpv.io/manual/master/#options-screen) - [border](https://mpv.io/manual/master/#options-border)
- [fullscreen](https://mpv.io/manual/master/#options-fullscreen)
[fullscreen](https://mpv.io/manual/master/#options-fullscreen) - [ontop](https://mpv.io/manual/master/#options-ontop)
- [screen](https://mpv.io/manual/master/#options-screen)
[ontop](https://mpv.io/manual/master/#options-ontop) - [title](https://mpv.io/manual/master/#options-title)
- [window-maximized](https://mpv.io/manual/master/#options-window-maximized)
[border](https://mpv.io/manual/master/#options-border) - [window-minimized](https://mpv.io/manual/master/#options-window-minimized)
[window-minimized](https://mpv.io/manual/master/#options-window-minimized)
[window-maximized](https://mpv.io/manual/master/#options-window-maximized)
**Partly implemented are:** **Partly implemented are:**

View File

@@ -49,10 +49,6 @@ 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)
{ {
@@ -92,7 +88,6 @@ namespace mpvnet
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 = string.IsNullOrEmpty(core.Title) ? "mpv.net " + Application.ProductVersion : core.Title;
TaskbarButtonCreatedMessage = RegisterWindowMessage("TaskbarButtonCreated"); TaskbarButtonCreatedMessage = RegisterWindowMessage("TaskbarButtonCreated");
ContextMenu = new ContextMenuStripEx(components); ContextMenu = new ContextMenuStripEx(components);
@@ -167,10 +162,7 @@ namespace mpvnet
void Shutdown() => BeginInvoke(new Action(() => Close())); void Shutdown() => BeginInvoke(new Action(() => Close()));
void Idle() void Idle() => SetTitle();
{
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;
@@ -524,15 +516,7 @@ 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)) Text = core.expand(Title);
{
if (path.Contains("://"))
Text = core.get_property_string("media-title") + " - mpv.net " + Application.ProductVersion;
else
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);
@@ -555,6 +539,8 @@ namespace mpvnet
RecentFiles.RemoveAt(App.RecentCount); RecentFiles.RemoveAt(App.RecentCount);
} }
void SetTitle() => BeginInvoke(new Action(() => Text = core.expand(Title)));
void SaveWindowProperties() void SaveWindowProperties()
{ {
if (WindowState == FormWindowState.Normal) if (WindowState == FormWindowState.Normal)
@@ -573,6 +559,21 @@ namespace mpvnet
} }
} }
string _Title;
public string Title {
get => _Title;
set {
if (string.IsNullOrEmpty(value))
return;
if (value.EndsWith("} - mpv"))
value = value.Replace("} - mpv", "} - mpv.net");
_Title = value;
}
}
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
{ {
//Debug.WriteLine(m); //Debug.WriteLine(m);
@@ -750,10 +751,7 @@ namespace mpvnet
void PropChangeVid(string value) => core.Vid = value; void PropChangeVid(string value) => core.Vid = value;
void PropChangeTitle(string value) => BeginInvoke(new Action(() => { void PropChangeTitle(string value) { Title = value; SetTitle(); }
if (value != null && !value.EndsWith("} - mpv"))
Text = value;
}));
void PropChangeEdition(int value) => core.Edition = value; void PropChangeEdition(int value) => core.Edition = value;

View File

@@ -100,7 +100,6 @@ namespace mpvnet
public string GPUAPI { get; set; } = "auto"; public string GPUAPI { get; set; } = "auto";
public string InputConfPath { get => ConfigFolder + "input.conf"; } public string InputConfPath { get => ConfigFolder + "input.conf"; }
public string Sid { get; set; } = ""; public string Sid { get; set; } = "";
public string Title { get; set; } = "";
public string Vid { get; set; } = ""; public string Vid { get; set; } = "";
public bool Border { get; set; } = true; public bool Border { get; set; } = true;
@@ -178,7 +177,6 @@ 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)
@@ -684,6 +682,12 @@ namespace mpvnet
public string expand(string value) public string expand(string value)
{ {
if (value == null)
return "";
if (!value.Contains("${"))
return value;
string[] args = { "expand-text", value }; string[] args = { "expand-text", value };
int count = args.Length + 1; int count = args.Length + 1;
IntPtr[] pointers = new IntPtr[count]; IntPtr[] pointers = new IntPtr[count];