This commit is contained in:
Frank Skare
2019-03-23 15:42:57 +01:00
parent f2c526348d
commit e7d41ff626
6 changed files with 68 additions and 37 deletions

View File

@@ -121,6 +121,12 @@ Please note that PowerShell don't allow assigning to events and mpv.net uses as
### Changes ### Changes
### 1.7
- showing the conf files mpv.net uses now the app that is registered for txt files, before it just shell executed the conf file which only worked if conf files were associated with an application
- leaving fullscreen mode the previous window size and position wasn't restored
- when the source video aspect ratio changes the height is kept and the width is adjusted and a check is performed to assure the window is within screen bounds
### 1.6 ### 1.6
- a crash caused by WM_APPCOMMAND (multimedia keyboards) commands was fixed - a crash caused by WM_APPCOMMAND (multimedia keyboards) commands was fixed
@@ -157,29 +163,3 @@ Please note that PowerShell don't allow assigning to events and mpv.net uses as
### 1.0 ### 1.0
- much more feature packed context menu - much more feature packed context menu
### 0.2.5
- mpv lib updated to 2019-02-24
- UI glitch fixed the appeared when started in fullscreen mode
- fixed default video output mode which caused video playback to fail
### 0.2.4
- changed minimum runtime to .NET 4.7.2
- fixed mpv.net not working with new mpv lib
- the track name in the title bar was sometimes wrong
- mpv lib updated to 2018-12-16
- quit-watch-later added to context menu (Shift+Q) to exit and resume at the last position
- ab loop added to menu
- added the possibility to modify mpv.conf settings using the context menu
- added link to the manual and default keys to the menu
### 0.2.2
- history feature added
- mpv lib updated
### 0.2.1
- right-click in fullscreen in the right-left corner closes the app

View File

@@ -62,12 +62,12 @@ namespace mpvnet
public static void show_keys(string[] args) public static void show_keys(string[] args)
{ {
Process.Start(mp.InputConfPath); Process.Start(NativeHelp.GetAssociatedApplication(".txt"), mp.InputConfPath);
} }
public static void show_prefs(string[] args) public static void show_prefs(string[] args)
{ {
Process.Start(mp.mpvConfPath); Process.Start(NativeHelp.GetAssociatedApplication(".txt"), mp.mpvConfPath);
} }
public static void history(string[] args) public static void history(string[] args)
@@ -148,7 +148,7 @@ namespace mpvnet
bitrate = "0"; bitrate = "0";
var bitrate2 = Convert.ToDouble(bitrate) / 1000.0 / 1000.0; var bitrate2 = Convert.ToDouble(bitrate) / 1000.0 / 1000.0;
var format = mp.get_property_string("video-format").ToUpper(); var videoCodec = mp.get_property_string("video-format").ToUpper();
var filename = fileInfo.Name; var filename = fileInfo.Name;
var text = var text =
@@ -157,7 +157,7 @@ namespace mpvnet
FormatTime(duration.TotalMinutes) + ":" + FormatTime(duration.TotalMinutes) + ":" +
FormatTime(duration.Seconds) + "\n" + FormatTime(duration.Seconds) + "\n" +
Convert.ToInt32(fileInfo.Length / 1024 / 1024).ToString() + Convert.ToInt32(fileInfo.Length / 1024 / 1024).ToString() +
$" MB - {width} x {height}\n{format} - {bitrate2.ToString("f1")} Mb/s" + "\n" + filename; $" MB - {width} x {height}\n{videoCodec} - {bitrate2.ToString("f1")} Mb/s" + "\n" + filename;
mp.commandv("show-text", text, "5000"); mp.commandv("show-text", text, "5000");
} }

View File

@@ -61,10 +61,10 @@ namespace mpvnet
Rectangle target = screen.Bounds; Rectangle target = screen.Bounds;
Left = target.X + Convert.ToInt32((target.Width - Width) / 2.0); Left = target.X + Convert.ToInt32((target.Width - Width) / 2.0);
Top = target.Y + Convert.ToInt32((target.Height - Height) / 2.0); Top = target.Y + Convert.ToInt32((target.Height - Height) / 2.0);
SetFormPositionAndSize(); SetStartFormPositionAndSize();
} }
void SetFormPositionAndSize() void SetStartFormPositionAndSize()
{ {
if (IsFullscreen || mp.VideoSize.Width == 0) return; if (IsFullscreen || mp.VideoSize.Width == 0) return;
Screen screen = Screen.FromControl(this); Screen screen = Screen.FromControl(this);
@@ -78,6 +78,30 @@ namespace mpvnet
Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */); Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */);
} }
void SetFormPositionAndSizeKeepHeight()
{
if (IsFullscreen || mp.VideoSize.Width == 0) return;
Screen screen = Screen.FromControl(this);
int height = ClientSize.Height;
int width = Convert.ToInt32(height * mp.VideoSize.Width / (double)mp.VideoSize.Height);
Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
var rect = new Native.RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height));
NativeHelp.AddWindowBorders(Handle, ref rect);
int left = middlePos.X - rect.Width / 2;
int top = middlePos.Y - rect.Height / 2;
Screen[] screens = Screen.AllScreens;
if (left < screens[0].Bounds.Left)
left = screens[0].Bounds.Left;
int maxLeft = screens[0].Bounds.Left + screens.Select((sc) => sc.Bounds.Width).Sum() - rect.Width - SystemInformation.CaptionHeight;
if (left > maxLeft)
left = maxLeft;
Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */);
}
protected void ProcessCommandLineEarly() protected void ProcessCommandLineEarly()
{ {
var args = Environment.GetCommandLineArgs().Skip(1); var args = Environment.GetCommandLineArgs().Skip(1);
@@ -186,7 +210,7 @@ namespace mpvnet
private void mp_VideoSizeChanged() private void mp_VideoSizeChanged()
{ {
BeginInvoke(new Action(() => SetFormPositionAndSize())); BeginInvoke(new Action(() => SetFormPositionAndSizeKeepHeight()));
} }
private void mp_Shutdown() private void mp_Shutdown()
@@ -218,7 +242,7 @@ namespace mpvnet
{ {
WindowState = FormWindowState.Normal; WindowState = FormWindowState.Normal;
FormBorderStyle = FormBorderStyle.Sizable; FormBorderStyle = FormBorderStyle.Sizable;
SetFormPositionAndSize(); SetFormPositionAndSizeKeepHeight();
} }
} }

View File

@@ -1,6 +1,8 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
namespace mpvnet namespace mpvnet
{ {
@@ -30,6 +32,9 @@ namespace mpvnet
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags); public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
[DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern uint AssocQueryString(uint flags, uint str, string pszAssoc, string pszExtra, StringBuilder pszOut, ref uint pcchOut);
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct RECT public struct RECT
{ {

View File

@@ -1,4 +1,6 @@
using System; using System;
using System.IO;
using System.Text;
namespace mpvnet namespace mpvnet
{ {
@@ -34,5 +36,25 @@ namespace mpvnet
{ {
Native.AdjustWindowRect(ref rc, (uint)Native.GetWindowLongPtrW(hwnd, -16 /* GWL_STYLE */), false); Native.AdjustWindowRect(ref rc, (uint)Native.GetWindowLongPtrW(hwnd, -16 /* GWL_STYLE */), false);
} }
public static string GetAssociatedApplication(string ext)
{
uint returnValue = 0U;
// ASSOCF_VERIFY, ASSOCSTR_EXECUTABLE
if (1 == Native.AssocQueryString(0x40, 2, ext, null, null, ref returnValue))
{
if (returnValue > 0)
{
StringBuilder sb = new StringBuilder(Convert.ToInt32(returnValue));
// ASSOCF_VERIFY, ASSOCSTR_EXECUTABLE
if (0 == Native.AssocQueryString(0x40, 2, ext, null, sb, ref returnValue))
{
var ret = sb.ToString();
if (File.Exists(ret)) return ret;
}
}
}
return "";
}
} }
} }

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.0.0")] [assembly: AssemblyVersion("1.7.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")] [assembly: AssemblyFileVersion("1.7.0.0")]