Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d16861b0b | ||
|
|
4366c47a09 | ||
|
|
fc3dd45b72 | ||
|
|
66cf3a9b2f | ||
|
|
a9c2150c47 | ||
|
|
b77bbd5aec | ||
|
|
92b58873e2 | ||
|
|
c8214b2d94 | ||
|
|
f77defecfd | ||
|
|
6fec4bada7 | ||
|
|
c508761c36 | ||
|
|
3fd1285ad8 | ||
|
|
91a67c29a7 | ||
|
|
c8ce0b6dfc |
98
README.md
98
README.md
@@ -9,9 +9,9 @@ mpv manual: https://mpv.io/manual/master/
|
|||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Customizable context menu defined in the same file as the keybindings
|
- Customizable context menu defined in the same file as the keybindings
|
||||||
- Addons support for using .NET languages
|
- Addon API for .NET languages
|
||||||
- C# scripts implemented with CS-Script
|
- 5 different scripting languages are supported, Python scripting implemented with IronPython, C# implemented with CS-Script, Lua and JavaScript implemented in libmpv and PowerShell
|
||||||
- mpv's OSC, IPC, Lua/JS, conf files and more
|
- mpv's OSC, IPC, conf files and more
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -21,13 +21,19 @@ The context menu can be customized via input.conf file located at:
|
|||||||
|
|
||||||
C:\Users\Frank\AppData\Roaming\mpv\input.conf
|
C:\Users\Frank\AppData\Roaming\mpv\input.conf
|
||||||
|
|
||||||
if it misses mpv.net generates it with the following defaults:
|
if it's missing mpv.net generates it with the following defaults:
|
||||||
|
|
||||||
https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input_conf.txt
|
https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt
|
||||||
|
|
||||||
### C# Scripting
|
### C# Scripting
|
||||||
|
|
||||||
A simple C# script located at: C:\Users\Frank\AppData\Roaming\mpv\scripts\test.cs
|
A simple C# script located at:
|
||||||
|
|
||||||
|
C:\Users\Frank\AppData\Roaming\mpv\scripts\test.cs
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
startup\scripts\test.cs
|
||||||
|
|
||||||
```
|
```
|
||||||
using mpvnet;
|
using mpvnet;
|
||||||
@@ -48,8 +54,88 @@ class Script
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Python Scripting
|
||||||
|
|
||||||
|
A simple Python script located at:
|
||||||
|
|
||||||
|
C:\Users\user\AppData\Roaming\mpv\scripts
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
startup\scripts
|
||||||
|
|
||||||
|
```
|
||||||
|
# when seeking displays position and
|
||||||
|
# duration like so: 70:00 / 80:00
|
||||||
|
# which is different from mpv which
|
||||||
|
# uses 01:10:00 / 01:20:00
|
||||||
|
|
||||||
|
import math
|
||||||
|
|
||||||
|
def seek():
|
||||||
|
mp.commandv('show-text',
|
||||||
|
format(mp.get_property_number("time-pos")) + " / " + format(mp.get_property_number("duration")))
|
||||||
|
|
||||||
|
def format(f):
|
||||||
|
sec = round(f)
|
||||||
|
|
||||||
|
if sec < 0:
|
||||||
|
sec = 0
|
||||||
|
|
||||||
|
pos_min_floor = math.floor(sec / 60)
|
||||||
|
sec_rest = sec - pos_min_floor * 60
|
||||||
|
return add_zero(pos_min_floor) + ":" + add_zero(sec_rest)
|
||||||
|
|
||||||
|
def add_zero(val):
|
||||||
|
val = round(val)
|
||||||
|
return "" + str(int(val)) if (val > 9) else "0" + str(int(val))
|
||||||
|
|
||||||
|
mp.register_event("seek", seek) # or use: mp.Seek += seek
|
||||||
|
```
|
||||||
|
|
||||||
|
### PowerShell Scripting
|
||||||
|
|
||||||
|
A simple PowerShell script located at:
|
||||||
|
|
||||||
|
C:\Users\user\AppData\Roaming\mpv\scripts
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
startup\scripts
|
||||||
|
|
||||||
|
Please note that PowerShell don't allow assigning to events and mpv.net uses as workaround the script filename.
|
||||||
|
|
||||||
|
```
|
||||||
|
$position = [mp]::get_property_number("time-pos");
|
||||||
|
[mp]::commandv("show-text", $position.ToString() + " seconds")
|
||||||
|
```
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
|
### not yet released
|
||||||
|
|
||||||
|
### 1.5
|
||||||
|
|
||||||
|
- the info command supports now info for music files instead of showing an exception on music files
|
||||||
|
- added support for WM_APPCOMMAND API to support media keyboards
|
||||||
|
- fixed Alt key input not working
|
||||||
|
- mpv.net API methods renamed to match the names used in the Lua/JS API
|
||||||
|
|
||||||
|
### 1.4
|
||||||
|
|
||||||
|
- the last thread sync fix wasn't working well, the delayed shutdown should be gone for good now
|
||||||
|
- libmpv updated
|
||||||
|
|
||||||
|
### 1.3
|
||||||
|
|
||||||
|
- besides Lua/JavaScript/C#/Python there is now PowerShell supported as fifth scripting language
|
||||||
|
|
||||||
|
- in case there isn't yet a mpv.conf file mpv.net creates the file with certain default settings that were previously set on every mpv.net start. This was changed to provide transparency on which settings mpv.net uses. These default settings can be seen here: https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpv.conf.txt
|
||||||
|
|
||||||
|
### 1.2
|
||||||
|
|
||||||
|
- a thread synchonisation bug which caused the shutdown to be delayed or frozen was fixed, it also caused the Shutdown event not to fire which caused the rating plugin not to work
|
||||||
|
|
||||||
### 1.1
|
### 1.1
|
||||||
|
|
||||||
- added support for Python scripting via IronPython
|
- added support for Python scripting via IronPython
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ namespace RatingAddon
|
|||||||
if (args?.Length != 2 || args[0] != "rate-file" || ! int.TryParse(args[1], out rating))
|
if (args?.Length != 2 || args[0] != "rate-file" || ! int.TryParse(args[1], out rating))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Dic[mp.GetStringProp("path")] = rating;
|
Dic[mp.get_property_string("path")] = rating;
|
||||||
mp.Command("show-text", $"Rating: {rating}");
|
mp.commandv("show-text", $"Rating: {rating}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,20 +65,8 @@ namespace mpvnet
|
|||||||
Process.Start(mp.InputConfPath);
|
Process.Start(mp.InputConfPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateMpvConf()
|
|
||||||
{
|
|
||||||
if (!File.Exists(mp.mpvConfPath))
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(mp.mpvConfFolderPath))
|
|
||||||
Directory.CreateDirectory(mp.mpvConfFolderPath);
|
|
||||||
|
|
||||||
File.WriteAllText(mp.mpvConfPath, "# https://mpv.io/manual/master/#configuration-files");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void show_prefs(string[] args)
|
public static void show_prefs(string[] args)
|
||||||
{
|
{
|
||||||
CreateMpvConf();
|
|
||||||
Process.Start(mp.mpvConfPath);
|
Process.Start(mp.mpvConfPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +77,7 @@ namespace mpvnet
|
|||||||
if (File.Exists(fp))
|
if (File.Exists(fp))
|
||||||
Process.Start(fp);
|
Process.Start(fp);
|
||||||
else
|
else
|
||||||
if (MsgQuestion("Create history.txt file in config folder?\r\n\r\nmpv.net will write the date, time and filename of opened files to it.") == DialogResult.OK)
|
if (MsgQuestion("Create history.txt file in config folder?\n\nmpv.net will write the date, time and filename of opened files to it.") == DialogResult.OK)
|
||||||
File.WriteAllText(fp, "");
|
File.WriteAllText(fp, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,8 +88,6 @@ namespace mpvnet
|
|||||||
|
|
||||||
public static void set_setting(string[] args)
|
public static void set_setting(string[] args)
|
||||||
{
|
{
|
||||||
CreateMpvConf();
|
|
||||||
|
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
string fp = mp.mpvConfPath;
|
string fp = mp.mpvConfPath;
|
||||||
var confLines = File.ReadAllLines(fp);
|
var confLines = File.ReadAllLines(fp);
|
||||||
@@ -116,51 +102,67 @@ namespace mpvnet
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
|
||||||
File.WriteAllText(fp, String.Join(Environment.NewLine, confLines));
|
File.WriteAllText(fp, String.Join(Environment.NewLine, confLines));
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
File.WriteAllText(fp, File.ReadAllText(fp) + Environment.NewLine + args[0] + "=" + args[1]);
|
||||||
File.WriteAllText(fp,
|
|
||||||
File.ReadAllText(fp) + Environment.NewLine + args[0] + "=" + args[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
MsgInfo("Please restart mpv.net");
|
MsgInfo("Please restart mpv.net");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void show_info(string[] args)
|
public static void show_info(string[] args)
|
||||||
{
|
{
|
||||||
var fi = new FileInfo(mp.GetStringProp("path"));
|
var fileInfo = new FileInfo(mp.get_property_string("path"));
|
||||||
|
|
||||||
using (var mi = new MediaInfo(fi.FullName))
|
using (var mediaInfo = new MediaInfo(fileInfo.FullName))
|
||||||
{
|
{
|
||||||
var w = mi.GetInfo(MediaInfoStreamKind.Video, "Width");
|
string width = mediaInfo.GetInfo(MediaInfoStreamKind.Video, "Width");
|
||||||
var h = mi.GetInfo(MediaInfoStreamKind.Video, "Height");
|
|
||||||
var pos = TimeSpan.FromSeconds(mp.GetIntProp("time-pos"));
|
|
||||||
var dur = TimeSpan.FromSeconds(mp.GetIntProp("duration"));
|
|
||||||
string mibr = mi.GetInfo(MediaInfoStreamKind.Video, "BitRate");
|
|
||||||
|
|
||||||
if (mibr == "")
|
if (width == "")
|
||||||
mibr = "0";
|
{
|
||||||
|
string performer = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Performer");
|
||||||
|
string title = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Title");
|
||||||
|
string album = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Album");
|
||||||
|
string genre = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Genre");
|
||||||
|
string date = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Recorded_Date");
|
||||||
|
string duration = mediaInfo.GetInfo(MediaInfoStreamKind.Audio, "Duration/String");
|
||||||
|
|
||||||
var br = Convert.ToInt32(mibr) / 1000.0 / 1000.0;
|
string text = "";
|
||||||
var vf = mp.GetStringProp("video-format").ToUpper();
|
|
||||||
var fn = fi.Name;
|
|
||||||
|
|
||||||
if (fn.Length > 60)
|
if (performer != "") text += "Artist: " + performer + "\n";
|
||||||
fn = fn.Insert(59, "\r\n");
|
if (title != "") text += "Title: " + title + "\n";
|
||||||
|
if (album != "") text += "Album: " + album + "\n";
|
||||||
|
if (genre != "") text += "Genre: " + genre + "\n";
|
||||||
|
if (date != "") text += "Year: " + date + "\n";
|
||||||
|
if (duration != "") text += "Length: " + duration + "\n";
|
||||||
|
|
||||||
var info =
|
mp.commandv("show-text", text, "5000");
|
||||||
FormatTime(pos.TotalMinutes) + ":" +
|
}
|
||||||
FormatTime(pos.Seconds) + " / " +
|
else
|
||||||
FormatTime(dur.TotalMinutes) + ":" +
|
{
|
||||||
FormatTime(dur.Seconds) + "\n" +
|
string height = mediaInfo.GetInfo(MediaInfoStreamKind.Video, "Height");
|
||||||
((int)(fi.Length / 1024 / 1024)).ToString() +
|
TimeSpan position = TimeSpan.FromSeconds(mp.get_property_number("time-pos"));
|
||||||
$" MB - {w} x {h}\n{vf} - {br.ToString("f1")} Mb/s" + "\n" + fn;
|
TimeSpan duration = TimeSpan.FromSeconds(mp.get_property_number("duration"));
|
||||||
|
string bitrate = mediaInfo.GetInfo(MediaInfoStreamKind.Video, "BitRate");
|
||||||
|
|
||||||
mp.Command("show-text", info, "5000");
|
if (bitrate == "")
|
||||||
|
bitrate = "0";
|
||||||
|
|
||||||
string FormatTime(double value) => ((int)(Math.Floor(value))).ToString("00");
|
var bitrate2 = Convert.ToDouble(bitrate) / 1000.0 / 1000.0;
|
||||||
|
var format = mp.get_property_string("video-format").ToUpper();
|
||||||
|
var filename = fileInfo.Name;
|
||||||
|
|
||||||
|
var text =
|
||||||
|
FormatTime(position.TotalMinutes) + ":" +
|
||||||
|
FormatTime(position.Seconds) + " / " +
|
||||||
|
FormatTime(duration.TotalMinutes) + ":" +
|
||||||
|
FormatTime(duration.Seconds) + "\n" +
|
||||||
|
Convert.ToInt32(fileInfo.Length / 1024 / 1024).ToString() +
|
||||||
|
$" MB - {width} x {height}\n{format} - {bitrate2.ToString("f1")} Mb/s" + "\n" + filename;
|
||||||
|
|
||||||
|
mp.commandv("show-text", text, "5000");
|
||||||
|
}
|
||||||
|
|
||||||
|
string FormatTime(double value) => ((int)value).ToString("00");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
mpv.net/MainForm.Designer.cs
generated
4
mpv.net/MainForm.Designer.cs
generated
@@ -42,17 +42,15 @@
|
|||||||
// MainForm
|
// MainForm
|
||||||
//
|
//
|
||||||
this.AllowDrop = true;
|
this.AllowDrop = true;
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||||
this.BackColor = System.Drawing.Color.Black;
|
this.BackColor = System.Drawing.Color.Black;
|
||||||
this.ClientSize = new System.Drawing.Size(1553, 1000);
|
this.ClientSize = new System.Drawing.Size(1012, 615);
|
||||||
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.Name = "MainForm";
|
this.Name = "MainForm";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "mpv.net";
|
this.Text = "mpv.net";
|
||||||
this.Load += new System.EventHandler(this.MainForm_Load);
|
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using System.IO;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using System.Diagnostics;
|
||||||
using static mpvnet.StaticUsing;
|
using static mpvnet.StaticUsing;
|
||||||
|
|
||||||
namespace mpvnet
|
namespace mpvnet
|
||||||
@@ -16,7 +16,6 @@ namespace mpvnet
|
|||||||
|
|
||||||
private Point LastCursorPosChanged;
|
private Point LastCursorPosChanged;
|
||||||
private int LastCursorChangedTickCount;
|
private int LastCursorChangedTickCount;
|
||||||
private bool IsCloseRequired = true;
|
|
||||||
|
|
||||||
public ContextMenuStripEx CMS;
|
public ContextMenuStripEx CMS;
|
||||||
|
|
||||||
@@ -27,14 +26,11 @@ namespace mpvnet
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Application.ThreadException += Application_ThreadException;
|
Application.ThreadException += Application_ThreadException;
|
||||||
SetFormPosSize();
|
SetFormPositionAndSize();
|
||||||
Instance = this;
|
Instance = this;
|
||||||
Hwnd = Handle;
|
Hwnd = Handle;
|
||||||
|
Text += " " + Application.ProductVersion;
|
||||||
ChangeFullscreen((mp.mpvConv.ContainsKey("fullscreen") && mp.mpvConv["fullscreen"] == "yes") || (mp.mpvConv.ContainsKey("fs") && mp.mpvConv["fs"] == "yes"));
|
ChangeFullscreen((mp.mpvConv.ContainsKey("fullscreen") && mp.mpvConv["fullscreen"] == "yes") || (mp.mpvConv.ContainsKey("fs") && mp.mpvConv["fs"] == "yes"));
|
||||||
CMS = new ContextMenuStripEx(components);
|
|
||||||
CMS.Opened += CMS_Opened;
|
|
||||||
ContextMenuStrip = CMS;
|
|
||||||
BuildMenu();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -44,14 +40,6 @@ namespace mpvnet
|
|||||||
|
|
||||||
public void BuildMenu()
|
public void BuildMenu()
|
||||||
{
|
{
|
||||||
if (!File.Exists(mp.InputConfPath))
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(mp.mpvConfFolderPath))
|
|
||||||
Directory.CreateDirectory(mp.mpvConfFolderPath);
|
|
||||||
|
|
||||||
File.WriteAllText(mp.InputConfPath, Properties.Resources.input_conf);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var i in File.ReadAllText(mp.InputConfPath).SplitLinesNoEmpty())
|
foreach (var i in File.ReadAllText(mp.InputConfPath).SplitLinesNoEmpty())
|
||||||
{
|
{
|
||||||
if (!i.Contains("#menu:"))
|
if (!i.Contains("#menu:"))
|
||||||
@@ -73,7 +61,7 @@ namespace mpvnet
|
|||||||
var menuItem = CMS.Add(path, () => {
|
var menuItem = CMS.Add(path, () => {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mp.CommandString(cmd, false);
|
mp.command_string(cmd);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -93,19 +81,25 @@ namespace mpvnet
|
|||||||
|
|
||||||
private string LastHistory;
|
private string LastHistory;
|
||||||
|
|
||||||
private void mpv_PlaybackRestart()
|
private void mp_PlaybackRestart()
|
||||||
{
|
{
|
||||||
var fn = mp.GetStringProp("filename");
|
var filename = mp.get_property_string("filename");
|
||||||
BeginInvoke(new Action(() => { Text = fn + " - mpv.net " + Application.ProductVersion; }));
|
BeginInvoke(new Action(() => { Text = filename + " - mpv.net " + Application.ProductVersion; }));
|
||||||
var fp = mp.mpvConfFolderPath + "history.txt";
|
var historyFilepath = mp.mpvConfFolderPath + "history.txt";
|
||||||
|
|
||||||
if (LastHistory != fn && File.Exists(fp))
|
if (LastHistory != filename && File.Exists(historyFilepath))
|
||||||
{
|
{
|
||||||
File.AppendAllText(fp, DateTime.Now.ToString() + " " + Path.GetFileNameWithoutExtension(fn) + "\r\n");
|
File.AppendAllText(historyFilepath, DateTime.Now.ToString() + " " +
|
||||||
LastHistory = fn;
|
Path.GetFileNameWithoutExtension(filename) + "\r\n");
|
||||||
|
LastHistory = filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Mp_Idle()
|
||||||
|
{
|
||||||
|
BeginInvoke(new Action(() => { Text = "mpv.net " + Application.ProductVersion; }));
|
||||||
|
}
|
||||||
|
|
||||||
private void CM_Popup(object sender, EventArgs e)
|
private void CM_Popup(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
CursorHelp.Show();
|
CursorHelp.Show();
|
||||||
@@ -121,15 +115,14 @@ namespace mpvnet
|
|||||||
MsgError(e.ToString());
|
MsgError(e.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Mpv_VideoSizeChanged()
|
private void mp_VideoSizeChanged()
|
||||||
{
|
{
|
||||||
BeginInvoke(new Action(() => SetFormPosSize()));
|
BeginInvoke(new Action(() => SetFormPositionAndSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Mpv_AfterShutdown()
|
private void mp_Shutdown()
|
||||||
{
|
{
|
||||||
if (IsCloseRequired)
|
BeginInvoke(new Action(() => Close()));
|
||||||
Invoke(new Action(() => Close()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsFullscreen
|
public bool IsFullscreen
|
||||||
@@ -137,7 +130,7 @@ namespace mpvnet
|
|||||||
get => WindowState == FormWindowState.Maximized;
|
get => WindowState == FormWindowState.Maximized;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpvChangeFullscreen(bool value)
|
void mp_ChangeFullscreen(bool value)
|
||||||
{
|
{
|
||||||
BeginInvoke(new Action(() => ChangeFullscreen(value)));
|
BeginInvoke(new Action(() => ChangeFullscreen(value)));
|
||||||
}
|
}
|
||||||
@@ -153,7 +146,7 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
WindowState = FormWindowState.Normal;
|
WindowState = FormWindowState.Normal;
|
||||||
FormBorderStyle = FormBorderStyle.Sizable;
|
FormBorderStyle = FormBorderStyle.Sizable;
|
||||||
SetFormPosSize();
|
SetFormPositionAndSize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,9 +162,21 @@ namespace mpvnet
|
|||||||
if (mp.MpvWindowHandle != IntPtr.Zero)
|
if (mp.MpvWindowHandle != IntPtr.Zero)
|
||||||
Native.SendMessage(mp.MpvWindowHandle, m.Msg, m.WParam, m.LParam);
|
Native.SendMessage(mp.MpvWindowHandle, m.Msg, m.WParam, m.LParam);
|
||||||
break;
|
break;
|
||||||
|
case 0x319: // WM_APPCOMMAND
|
||||||
|
if (mp.MpvWindowHandle != IntPtr.Zero)
|
||||||
|
Native.SendMessage(mp.MpvWindowHandle, m.Msg, m.WParam, m.LParam);
|
||||||
|
break;
|
||||||
|
case 0x0104: // WM_SYSKEYDOWN:
|
||||||
|
if (mp.MpvWindowHandle != IntPtr.Zero)
|
||||||
|
Native.SendMessage(mp.MpvWindowHandle, m.Msg, m.WParam, m.LParam);
|
||||||
|
break;
|
||||||
|
case 0x0105: // WM_SYSKEYUP:
|
||||||
|
if (mp.MpvWindowHandle != IntPtr.Zero)
|
||||||
|
Native.SendMessage(mp.MpvWindowHandle, m.Msg, m.WParam, m.LParam);
|
||||||
|
break;
|
||||||
case 0x203: // Native.WM.LBUTTONDBLCLK
|
case 0x203: // Native.WM.LBUTTONDBLCLK
|
||||||
if (!IsMouseInOSC())
|
if (!IsMouseInOSC())
|
||||||
mp.CommandString("cycle fullscreen");
|
mp.command_string("cycle fullscreen");
|
||||||
break;
|
break;
|
||||||
case 0x0214: // WM_SIZING
|
case 0x0214: // WM_SIZING
|
||||||
var rc = Marshal.PtrToStructure<Native.RECT>(m.LParam);
|
var rc = Marshal.PtrToStructure<Native.RECT>(m.LParam);
|
||||||
@@ -196,7 +201,7 @@ namespace mpvnet
|
|||||||
base.WndProc(ref m);
|
base.WndProc(ref m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFormPosSize()
|
void SetFormPositionAndSize()
|
||||||
{
|
{
|
||||||
if (IsFullscreen || mp.VideoSize.Width == 0) return;
|
if (IsFullscreen || mp.VideoSize.Width == 0) return;
|
||||||
var wa = Screen.GetWorkingArea(this);
|
var wa = Screen.GetWorkingArea(this);
|
||||||
@@ -249,7 +254,7 @@ namespace mpvnet
|
|||||||
var p2 = PointToScreen(e.Location);
|
var p2 = PointToScreen(e.Location);
|
||||||
|
|
||||||
if (Math.Abs(p1.X - p2.X) < 10 && Math.Abs(p1.Y - p2.Y) < 10)
|
if (Math.Abs(p1.X - p2.X) < 10 && Math.Abs(p1.Y - p2.Y) < 10)
|
||||||
mp.Command("quit");
|
mp.commandv("quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnMouseMove(MouseEventArgs e)
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
@@ -257,19 +262,12 @@ namespace mpvnet
|
|||||||
base.OnMouseMove(e);
|
base.OnMouseMove(e);
|
||||||
|
|
||||||
// send mouse command to make OSC show
|
// send mouse command to make OSC show
|
||||||
mp.CommandString($"mouse {e.X} {e.Y}");
|
mp.command_string($"mouse {e.X} {e.Y}");
|
||||||
|
|
||||||
if (CursorHelp.IsPosDifferent(LastCursorPosChanged))
|
if (CursorHelp.IsPosDifferent(LastCursorPosChanged))
|
||||||
CursorHelp.Show();
|
CursorHelp.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnFormClosed(FormClosedEventArgs e)
|
|
||||||
{
|
|
||||||
base.OnFormClosed(e);
|
|
||||||
IsCloseRequired = false;
|
|
||||||
mp.Command("quit");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsMouseInOSC()
|
bool IsMouseInOSC()
|
||||||
{
|
{
|
||||||
return PointToClient(Control.MousePosition).Y > ClientSize.Height * 0.9;
|
return PointToClient(Control.MousePosition).Y > ClientSize.Height * 0.9;
|
||||||
@@ -290,13 +288,31 @@ namespace mpvnet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_Load(object sender, EventArgs ea)
|
protected override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
|
base.OnLoad(e);
|
||||||
mp.Init();
|
mp.Init();
|
||||||
mp.ObserveBoolProp("fullscreen", MpvChangeFullscreen);
|
mp.observe_property_bool("fullscreen", mp_ChangeFullscreen);
|
||||||
mp.Shutdown += Mpv_AfterShutdown;
|
mp.Shutdown += mp_Shutdown;
|
||||||
mp.VideoSizeChanged += Mpv_VideoSizeChanged;
|
mp.VideoSizeChanged += mp_VideoSizeChanged;
|
||||||
mp.PlaybackRestart += mpv_PlaybackRestart;
|
mp.PlaybackRestart += mp_PlaybackRestart;
|
||||||
|
mp.Idle += Mp_Idle;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnShown(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnShown(e);
|
||||||
|
CMS = new ContextMenuStripEx(components);
|
||||||
|
CMS.Opened += CMS_Opened;
|
||||||
|
ContextMenuStrip = CMS;
|
||||||
|
BuildMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnFormClosed(FormClosedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnFormClosed(e);
|
||||||
|
mp.commandv("quit");
|
||||||
|
mp.AutoResetEvent.WaitOne(3000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
129
mpv.net/PowerShellScript.cs
Normal file
129
mpv.net/PowerShellScript.cs
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Management.Automation.Runspaces;
|
||||||
|
|
||||||
|
using static mpvnet.StaticUsing;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace mpvnet
|
||||||
|
{
|
||||||
|
public class PowerShellScript
|
||||||
|
{
|
||||||
|
public static object Execute(string code, string[] parameters)
|
||||||
|
{
|
||||||
|
using (Runspace runspace = RunspaceFactory.CreateRunspace())
|
||||||
|
{
|
||||||
|
runspace.ApartmentState = ApartmentState.STA;
|
||||||
|
runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;
|
||||||
|
runspace.Open();
|
||||||
|
|
||||||
|
using (Pipeline pipeline = runspace.CreatePipeline())
|
||||||
|
{
|
||||||
|
pipeline.Commands.AddScript(
|
||||||
|
@"Using namespace mpvnet;
|
||||||
|
Using namespace System;
|
||||||
|
[System.Reflection.Assembly]::LoadWithPartialName(""mpvnet"")");
|
||||||
|
|
||||||
|
pipeline.Commands.AddScript(code);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var ret = pipeline.Invoke(parameters);
|
||||||
|
|
||||||
|
if (ret.Count > 0)
|
||||||
|
return ret[0];
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (Pipeline pipeline2 = runspace.CreatePipeline())
|
||||||
|
{
|
||||||
|
pipeline2.Commands.AddScript("$PSVersionTable.PSVersion.Major * 10 +" +
|
||||||
|
"$PSVersionTable.PSVersion.Minor");
|
||||||
|
|
||||||
|
if (Convert.ToInt32(pipeline2.Invoke()[0].ToString()) < 51)
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
MsgError("PowerShell Setup Problem\r\n\r\nEnsure you have at least PowerShell 5.1 installed.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
MsgError(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Init(string filePath)
|
||||||
|
{
|
||||||
|
foreach (var eventInfo in typeof(mp).GetEvents())
|
||||||
|
{
|
||||||
|
if (eventInfo.Name.ToLower() ==
|
||||||
|
Path.GetFileNameWithoutExtension(filePath).ToLower().Replace("-", ""))
|
||||||
|
{
|
||||||
|
PowerShellEventObject eventObject = new PowerShellEventObject();
|
||||||
|
MethodInfo mi;
|
||||||
|
eventObject.FilePath = filePath;
|
||||||
|
|
||||||
|
if (eventInfo.EventHandlerType == typeof(Action))
|
||||||
|
{
|
||||||
|
mi = eventObject.GetType().GetMethod(nameof(PowerShellEventObject.Invoke));
|
||||||
|
}
|
||||||
|
else if (eventInfo.EventHandlerType == typeof(Action<EndFileEventMode>))
|
||||||
|
{
|
||||||
|
mi = eventObject.GetType().GetMethod(nameof(PowerShellEventObject.InvokeEndFileEventMode));
|
||||||
|
}
|
||||||
|
else if (eventInfo.EventHandlerType == typeof(Action<string[]>))
|
||||||
|
{
|
||||||
|
mi = eventObject.GetType().GetMethod(nameof(PowerShellEventObject.InvokeStrings));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new Exception();
|
||||||
|
|
||||||
|
eventObject.EventInfo = eventInfo;
|
||||||
|
Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, eventObject, mi);
|
||||||
|
eventObject.Delegate = handler;
|
||||||
|
eventInfo.AddEventHandler(eventObject, handler);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
PowerShellScript.Execute(File.ReadAllText(filePath), new string[] {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PowerShellEventObject
|
||||||
|
{
|
||||||
|
public EventInfo EventInfo { get; set; }
|
||||||
|
public Delegate Delegate { get; set; }
|
||||||
|
public string FilePath { get; set; }
|
||||||
|
|
||||||
|
public void Invoke()
|
||||||
|
{
|
||||||
|
Task.Run(() => { PowerShellScript.Execute(File.ReadAllText(FilePath), new string[] { }); });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InvokeEndFileEventMode(EndFileEventMode arg)
|
||||||
|
{
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
PowerShellScript.Execute(File.ReadAllText(FilePath), new string[] { arg.ToString() });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InvokeStrings(string[] args)
|
||||||
|
{
|
||||||
|
Task.Run(() => {
|
||||||
|
PowerShellScript.Execute(File.ReadAllText(FilePath), args);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
|
|||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
[assembly: AssemblyTitle("mpv.net")]
|
[assembly: AssemblyTitle("mpv.net")]
|
||||||
[assembly: AssemblyDescription("mpv/libmpv based player with pure mpv experience")]
|
[assembly: AssemblyDescription("libmpv based player with pure mpv experience")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("mpv.net")]
|
[assembly: AssemblyProduct("mpv.net")]
|
||||||
@@ -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.1.0.0")]
|
[assembly: AssemblyVersion("1.5.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
[assembly: AssemblyFileVersion("1.5.0.0")]
|
||||||
|
|||||||
28
mpv.net/Properties/Resources.Designer.cs
generated
28
mpv.net/Properties/Resources.Designer.cs
generated
@@ -19,7 +19,7 @@ namespace mpvnet.Properties {
|
|||||||
// class via a tool like ResGen or Visual Studio.
|
// class via a tool like ResGen or Visual Studio.
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||||
// with the /str option, or rebuild your VS project.
|
// with the /str option, or rebuild your VS project.
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
internal class Resources {
|
internal class Resources {
|
||||||
@@ -61,11 +61,37 @@ namespace mpvnet.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to # mpv.net key bindings, mouse bindings and context menu configuration
|
||||||
|
///
|
||||||
|
/// o script-message mpv.net open-files #menu: O ; Open Files...
|
||||||
|
/// _ ignore #menu: _ ; -
|
||||||
|
/// Space cycle pause #menu: Space, Enter ; Play/Pause
|
||||||
|
/// Enter cycle pause
|
||||||
|
/// s stop #menu: S ; Stop
|
||||||
|
/// _ ignore #menu: _ ; -
|
||||||
|
/// f cycle fullscreen #menu: F ; Toggle Fullscreen
/// [rest of string was truncated]";.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string input_conf {
|
internal static string input_conf {
|
||||||
get {
|
get {
|
||||||
return ResourceManager.GetString("input_conf", resourceCulture);
|
return ResourceManager.GetString("input_conf", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to input-ar-delay = 500
|
||||||
|
///input-ar-rate = 20
|
||||||
|
///volume = 50
|
||||||
|
///hwdec = yes
|
||||||
|
///vo = direct3d
|
||||||
|
///keep-open = yes
|
||||||
|
///keep-open-pause = no
|
||||||
|
///osd-playing-msg = '${filename}'
|
||||||
|
///screenshot-directory = ~~desktop/.
|
||||||
|
/// </summary>
|
||||||
|
internal static string mpv_conf {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("mpv_conf", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,6 +119,9 @@
|
|||||||
</resheader>
|
</resheader>
|
||||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
<data name="input_conf" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="input_conf" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>..\Resources\input_conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
<value>..\Resources\input.conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||||
|
</data>
|
||||||
|
<data name="mpv_conf" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\mpv.conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
using IronPython.Hosting;
|
|
||||||
using Microsoft.Scripting.Hosting;
|
|
||||||
|
|
||||||
using static mpvnet.StaticUsing;
|
|
||||||
|
|
||||||
namespace mpvnet
|
|
||||||
{
|
|
||||||
public class PyScript
|
|
||||||
{
|
|
||||||
ScriptEngine engine;
|
|
||||||
ScriptScope scope;
|
|
||||||
|
|
||||||
public PyScript(string code)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
engine = Python.CreateEngine();
|
|
||||||
scope = engine.CreateScope();
|
|
||||||
scope.ImportModule("clr");
|
|
||||||
engine.Execute("import clr", scope);
|
|
||||||
engine.Execute("clr.AddReference(\"mpvnet\")", scope);
|
|
||||||
engine.Execute("from mpvnet import *", scope);
|
|
||||||
engine.Execute(code, scope);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MsgError(ex.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
56
mpv.net/PythonScript.cs
Normal file
56
mpv.net/PythonScript.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using IronPython.Hosting;
|
||||||
|
using Microsoft.Scripting.Hosting;
|
||||||
|
|
||||||
|
using static mpvnet.StaticUsing;
|
||||||
|
using PyRT = IronPython.Runtime;
|
||||||
|
|
||||||
|
namespace mpvnet
|
||||||
|
{
|
||||||
|
public class PythonScript
|
||||||
|
{
|
||||||
|
ScriptEngine engine;
|
||||||
|
ScriptScope scope;
|
||||||
|
|
||||||
|
public PythonScript(string code)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
engine = Python.CreateEngine();
|
||||||
|
scope = engine.CreateScope();
|
||||||
|
scope.ImportModule("clr");
|
||||||
|
engine.Execute("import clr", scope);
|
||||||
|
engine.Execute("clr.AddReference(\"mpvnet\")", scope);
|
||||||
|
engine.Execute("from mpvnet import *", scope);
|
||||||
|
engine.Execute(code, scope);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MsgError(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PythonEventObject
|
||||||
|
{
|
||||||
|
public PyRT.PythonFunction PythonFunction { get; set; }
|
||||||
|
public EventInfo EventInfo { get; set; }
|
||||||
|
public Delegate Delegate { get; set; }
|
||||||
|
|
||||||
|
public void Invoke()
|
||||||
|
{
|
||||||
|
PyRT.Operations.PythonCalls.Call(PythonFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InvokeEndFileEventMode(EndFileEventMode arg)
|
||||||
|
{
|
||||||
|
PyRT.Operations.PythonCalls.Call(PythonFunction, new[] { arg });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InvokeStrings(string[] arg)
|
||||||
|
{
|
||||||
|
PyRT.Operations.PythonCalls.Call(PythonFunction, new[] { arg });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,16 +29,16 @@
|
|||||||
Ctrl++ add video-zoom 0.1 #menu: Ctrl++ ; Pan && Scan > Increase Size
|
Ctrl++ add video-zoom 0.1 #menu: Ctrl++ ; Pan && Scan > Increase Size
|
||||||
Ctrl+- add video-zoom -0.1 #menu: Ctrl+- ; Pan && Scan > Decrease Size
|
Ctrl+- add video-zoom -0.1 #menu: Ctrl+- ; Pan && Scan > Decrease Size
|
||||||
_ ignore #menu: _ ; Pan && Scan > -
|
_ ignore #menu: _ ; Pan && Scan > -
|
||||||
Shift+Left add video-pan-x -0.01 #menu: Shift+Left ; Pan && Scan > Move Left
|
Ctrl+KP4 add video-pan-x -0.01 #menu: Ctrl+Numpad 4 ; Pan && Scan > Move Left
|
||||||
Shift+Right add video-pan-x 0.01 #menu: Shift+Right ; Pan && Scan > Move Right
|
Ctrl+KP6 add video-pan-x 0.01 #menu: Ctrl+Numpad 6 ; Pan && Scan > Move Right
|
||||||
_ ignore #menu: _ ; Pan && Scan > -
|
_ ignore #menu: _ ; Pan && Scan > -
|
||||||
Shift+Up add video-pan-y -0.01 #menu: Shift+Up ; Pan && Scan > Move Up
|
Ctrl+KP8 add video-pan-y -0.01 #menu: Ctrl+Numpad 8 ; Pan && Scan > Move Up
|
||||||
Shift+Down add video-pan-y 0.01 #menu: Shift+Down ; Pan && Scan > Move Down
|
Ctrl+KP2 add video-pan-y 0.01 #menu: Ctrl+Numpad 2 ; Pan && Scan > Move Down
|
||||||
_ ignore #menu: _ ; Pan && Scan > -
|
_ ignore #menu: _ ; Pan && Scan > -
|
||||||
w add panscan -0.1 #menu: W ; Pan && Scan > Decrease Height
|
w add panscan -0.1 #menu: W ; Pan && Scan > Decrease Height
|
||||||
W add panscan +0.1 #menu: Shift+W ; Pan && Scan > Increase Height
|
W add panscan +0.1 #menu: Shift+W ; Pan && Scan > Increase Height
|
||||||
_ ignore #menu: _ ; Pan && Scan > -
|
_ ignore #menu: _ ; Pan && Scan > -
|
||||||
Shift+BS set video-zoom 0 ; set video-pan-x 0 ; set video-pan-y 0 #menu: Alt+Backspace ; Pan && Scan > Reset
|
Ctrl+BS set video-zoom 0 ; set video-pan-x 0 ; set video-pan-y 0 #menu: Shift+Backspace ; Pan && Scan > Reset
|
||||||
|
|
||||||
Ctrl+1 add contrast -1 #menu: Ctrl+1 ; Video > Decrease Contrast
|
Ctrl+1 add contrast -1 #menu: Ctrl+1 ; Video > Decrease Contrast
|
||||||
Ctrl+2 add contrast 1 #menu: Ctrl+2 ; Video > Increase Contrast
|
Ctrl+2 add contrast 1 #menu: Ctrl+2 ; Video > Increase Contrast
|
||||||
@@ -74,7 +74,6 @@
|
|||||||
_ ignore #menu: _ ; Subtitle > -
|
_ ignore #menu: _ ; Subtitle > -
|
||||||
_ add sub-scale -0.1 #menu: _ ; Subtitle > Decrease Subtitle Font Size
|
_ add sub-scale -0.1 #menu: _ ; Subtitle > Decrease Subtitle Font Size
|
||||||
_ add sub-scale +0.1 #menu: _ ; Subtitle > Increase Subtitle Font Size
|
_ add sub-scale +0.1 #menu: _ ; Subtitle > Increase Subtitle Font Size
|
||||||
_ ignore #menu: _ ; Subtitle > -
|
|
||||||
|
|
||||||
+ add volume 10 #menu: + ; Volume > Up
|
+ add volume 10 #menu: + ; Volume > Up
|
||||||
- add volume -10 #menu: - ; Volume > Down
|
- add volume -10 #menu: - ; Volume > Down
|
||||||
@@ -104,7 +103,7 @@
|
|||||||
k script-message mpv.net show-keys #menu: K ; Settings > Show Keys
|
k script-message mpv.net show-keys #menu: K ; Settings > Show Keys
|
||||||
c script-message mpv.net open-config-folder #menu: C ; Settings > Open Config Folder
|
c script-message mpv.net open-config-folder #menu: C ; Settings > Open Config Folder
|
||||||
|
|
||||||
i show-progress ; script-message mpv.net show-info #menu: I ; Tools | Info
|
i script-message mpv.net show-info #menu: I ; Tools | Info
|
||||||
t script-binding stats/display-stats #menu: T ; Tools > Show Statistics
|
t script-binding stats/display-stats #menu: T ; Tools > Show Statistics
|
||||||
T script-binding stats/display-stats-toggle #menu: Shift+T ; Tools > Toggle Statistics
|
T script-binding stats/display-stats-toggle #menu: Shift+T ; Tools > Toggle Statistics
|
||||||
_ ignore #menu: _ ; Tools > -
|
_ ignore #menu: _ ; Tools > -
|
||||||
@@ -116,9 +115,10 @@
|
|||||||
F8 show-text ${playlist} 5000 #menu: F8 ; Tools > Show Playlist
|
F8 show-text ${playlist} 5000 #menu: F8 ; Tools > Show Playlist
|
||||||
F9 show-text ${track-list} 5000 #menu: F9 ; Tools > Show Audio/Video/Subtitle List
|
F9 show-text ${track-list} 5000 #menu: F9 ; Tools > Show Audio/Video/Subtitle List
|
||||||
|
|
||||||
_ script-message mpv.net shell-execute https://mpv.io/manual/stable/ #menu: _ ; Tools > Web > Show mpv manual
|
_ script-message mpv.net shell-execute https://mpv.io/manual/stable/ #menu: _ ; Help > Show mpv manual
|
||||||
_ script-message mpv.net shell-execute https://github.com/mpv-player/mpv/blob/master/etc/input.conf #menu: _ ; Tools > Web > Show mpv default keys
|
_ script-message mpv.net shell-execute https://github.com/mpv-player/mpv/blob/master/etc/input.conf #menu: _ ; Help > Show mpv default keys
|
||||||
_ script-message mpv.net shell-execute https://github.com/stax76/mpvnet #menu: _ ; Tools > Web > Show mpv.net web site
|
_ script-message mpv.net shell-execute https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt #menu: _ ; Help > Show mpv.net default keys
|
||||||
|
_ script-message mpv.net shell-execute https://github.com/stax76/mpvnet #menu: _ ; Help > Show mpv.net web site
|
||||||
_ ignore #menu: _ ; -
|
_ ignore #menu: _ ; -
|
||||||
Esc quit #menu: Escape ; Exit
|
Esc quit #menu: Escape ; Exit
|
||||||
Q quit-watch-later #menu: Shift+Q ; Exit Watch Later
|
Q quit-watch-later #menu: Shift+Q ; Exit Watch Later
|
||||||
@@ -136,5 +136,3 @@
|
|||||||
VOLUME_UP add volume 2
|
VOLUME_UP add volume 2
|
||||||
VOLUME_DOWN add volume -2
|
VOLUME_DOWN add volume -2
|
||||||
MUTE cycle mute
|
MUTE cycle mute
|
||||||
CLOSE_WIN quit
|
|
||||||
CLOSE_WIN {encode} quit 4
|
|
||||||
11
mpv.net/Resources/mpv.conf.txt
Normal file
11
mpv.net/Resources/mpv.conf.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# https://mpv.io/manual/master/
|
||||||
|
|
||||||
|
input-ar-delay = 500
|
||||||
|
input-ar-rate = 20
|
||||||
|
volume = 50
|
||||||
|
hwdec = yes
|
||||||
|
vo = direct3d
|
||||||
|
keep-open = yes
|
||||||
|
keep-open-pause = no
|
||||||
|
osd-playing-msg = ${filename}
|
||||||
|
screenshot-directory = ~~desktop/
|
||||||
172
mpv.net/mp.cs
172
mpv.net/mp.cs
@@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
@@ -60,7 +61,8 @@ namespace mpvnet
|
|||||||
public static string mpvConfFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\";
|
public static string mpvConfFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\";
|
||||||
public static string InputConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\input.conf";
|
public static string InputConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\input.conf";
|
||||||
public static string mpvConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\mpv.conf";
|
public static string mpvConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\mpv.conf";
|
||||||
public static List<PyScript> PyScripts { get; } = new List<PyScript>();
|
public static List<PythonScript> PythonScripts { get; } = new List<PythonScript>();
|
||||||
|
public static AutoResetEvent AutoResetEvent = new AutoResetEvent(false);
|
||||||
|
|
||||||
private static Dictionary<string, string> _mpvConv;
|
private static Dictionary<string, string> _mpvConv;
|
||||||
|
|
||||||
@@ -71,15 +73,9 @@ namespace mpvnet
|
|||||||
_mpvConv = new Dictionary<string, string>();
|
_mpvConv = new Dictionary<string, string>();
|
||||||
|
|
||||||
if (File.Exists(mpvConfPath))
|
if (File.Exists(mpvConfPath))
|
||||||
{
|
|
||||||
foreach (var i in File.ReadAllLines(mpvConfPath))
|
foreach (var i in File.ReadAllLines(mpvConfPath))
|
||||||
{
|
|
||||||
if (i.Contains("=") && ! i.StartsWith("#"))
|
if (i.Contains("=") && ! i.StartsWith("#"))
|
||||||
{
|
|
||||||
_mpvConv[i.Left("=").Trim()] = i.Right("=").Trim();
|
_mpvConv[i.Left("=").Trim()] = i.Right("=").Trim();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return _mpvConv;
|
return _mpvConv;
|
||||||
}
|
}
|
||||||
@@ -87,22 +83,23 @@ namespace mpvnet
|
|||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
if (!Directory.Exists(mp.mpvConfFolderPath))
|
||||||
|
Directory.CreateDirectory(mp.mpvConfFolderPath);
|
||||||
|
|
||||||
|
if (!File.Exists(mp.mpvConfPath))
|
||||||
|
File.WriteAllText(mp.mpvConfPath, Properties.Resources.mpv_conf);
|
||||||
|
|
||||||
|
if (!File.Exists(mp.InputConfPath))
|
||||||
|
File.WriteAllText(mp.InputConfPath, Properties.Resources.input_conf);
|
||||||
|
|
||||||
LoadLibrary("mpv-1.dll");
|
LoadLibrary("mpv-1.dll");
|
||||||
MpvHandle = mpv_create();
|
MpvHandle = mpv_create();
|
||||||
SetIntProp("input-ar-delay", 500);
|
set_property_string("input-default-bindings", "yes");
|
||||||
SetIntProp("input-ar-rate", 20);
|
set_property_string("osc", "yes");
|
||||||
SetIntProp("volume", 50);
|
set_property_string("config", "yes");
|
||||||
SetStringProp("hwdec", "yes");
|
set_property_string("wid", MainForm.Hwnd.ToString());
|
||||||
SetStringProp("vo", "direct3d");
|
set_property_string("force-window", "yes");
|
||||||
SetStringProp("input-default-bindings", "yes");
|
set_property_string("input-media-keys", "yes");
|
||||||
SetStringProp("osd-playing-msg", "'${filename}'");
|
|
||||||
SetStringProp("screenshot-directory", "~~desktop/");
|
|
||||||
SetStringProp("keep-open", "yes");
|
|
||||||
SetStringProp("keep-open-pause", "no");
|
|
||||||
SetStringProp("osc", "yes");
|
|
||||||
SetStringProp("config", "yes");
|
|
||||||
SetStringProp("wid", MainForm.Hwnd.ToString());
|
|
||||||
SetStringProp("force-window", "yes");
|
|
||||||
mpv_initialize(MpvHandle);
|
mpv_initialize(MpvHandle);
|
||||||
ProcessCommandLine();
|
ProcessCommandLine();
|
||||||
Task.Run(() => { LoadScripts(); });
|
Task.Run(() => { LoadScripts(); });
|
||||||
@@ -117,14 +114,23 @@ namespace mpvnet
|
|||||||
|
|
||||||
foreach (var scriptPath in startupScripts)
|
foreach (var scriptPath in startupScripts)
|
||||||
if (jsLua.Contains(Path.GetExtension(scriptPath).ToLower()))
|
if (jsLua.Contains(Path.GetExtension(scriptPath).ToLower()))
|
||||||
mp.Command("load-script", $"{scriptPath}");
|
mp.commandv("load-script", $"{scriptPath}");
|
||||||
|
|
||||||
foreach (var scriptPath in startupScripts)
|
foreach (var scriptPath in startupScripts)
|
||||||
if (Path.GetExtension(scriptPath) == ".py")
|
if (Path.GetExtension(scriptPath) == ".py")
|
||||||
PyScripts.Add(new PyScript(File.ReadAllText(scriptPath)));
|
PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)));
|
||||||
|
|
||||||
foreach(var scriptPath in Directory.GetFiles(mp.mpvConfFolderPath + "scripts", "*.py"))
|
foreach (var scriptPath in startupScripts)
|
||||||
PyScripts.Add(new PyScript(File.ReadAllText(scriptPath)));
|
if (Path.GetExtension(scriptPath) == ".ps1")
|
||||||
|
PowerShellScript.Init(scriptPath);
|
||||||
|
|
||||||
|
foreach (var scriptPath in Directory.GetFiles(mp.mpvConfFolderPath + "Scripts"))
|
||||||
|
{
|
||||||
|
if (Path.GetExtension(scriptPath) == ".py")
|
||||||
|
PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)));
|
||||||
|
else if (Path.GetExtension(scriptPath) == ".ps1")
|
||||||
|
PowerShellScript.Init(scriptPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void EventLoop()
|
public static void EventLoop()
|
||||||
@@ -133,15 +139,17 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
IntPtr ptr = mpv_wait_event(MpvHandle, -1);
|
IntPtr ptr = mpv_wait_event(MpvHandle, -1);
|
||||||
mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));
|
mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));
|
||||||
//Debug.WriteLine(evt.event_id);
|
|
||||||
|
|
||||||
if (MpvWindowHandle == IntPtr.Zero)
|
if (MpvWindowHandle == IntPtr.Zero)
|
||||||
MpvWindowHandle = FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null);
|
MpvWindowHandle = FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null);
|
||||||
|
|
||||||
|
//Debug.WriteLine(evt.event_id.ToString());
|
||||||
|
|
||||||
switch (evt.event_id)
|
switch (evt.event_id)
|
||||||
{
|
{
|
||||||
case mpv_event_id.MPV_EVENT_SHUTDOWN:
|
case mpv_event_id.MPV_EVENT_SHUTDOWN:
|
||||||
Shutdown?.Invoke();
|
Shutdown?.Invoke();
|
||||||
|
AutoResetEvent.Set();
|
||||||
return;
|
return;
|
||||||
case mpv_event_id.MPV_EVENT_LOG_MESSAGE:
|
case mpv_event_id.MPV_EVENT_LOG_MESSAGE:
|
||||||
LogMessage?.Invoke();
|
LogMessage?.Invoke();
|
||||||
@@ -229,7 +237,7 @@ namespace mpvnet
|
|||||||
break;
|
break;
|
||||||
case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART:
|
case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART:
|
||||||
PlaybackRestart?.Invoke();
|
PlaybackRestart?.Invoke();
|
||||||
Size s = new Size(GetIntProp("dwidth", false), GetIntProp("dheight", false));
|
Size s = new Size(get_property_int("dwidth"), get_property_int("dheight"));
|
||||||
|
|
||||||
if (VideoSize != s && s != Size.Empty)
|
if (VideoSize != s && s != Size.Empty)
|
||||||
{
|
{
|
||||||
@@ -250,29 +258,7 @@ namespace mpvnet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EventObject
|
private static List<PythonEventObject> PythonEventObjects = new List<PythonEventObject>();
|
||||||
{
|
|
||||||
public PyRT.PythonFunction PythonFunction { get; set; }
|
|
||||||
public EventInfo EventInfo { get; set; }
|
|
||||||
public Delegate Delegate { get; set; }
|
|
||||||
|
|
||||||
public void Invoke()
|
|
||||||
{
|
|
||||||
PyRT.Operations.PythonCalls.Call(PythonFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InvokeEndFileEventMode(EndFileEventMode arg)
|
|
||||||
{
|
|
||||||
PyRT.Operations.PythonCalls.Call(PythonFunction, new[] { arg });
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InvokeStrings(string[] arg)
|
|
||||||
{
|
|
||||||
PyRT.Operations.PythonCalls.Call(PythonFunction, new[] { arg });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<EventObject> EventObjects = new List<EventObject>();
|
|
||||||
|
|
||||||
public static void register_event(string name, PyRT.PythonFunction pyFunc)
|
public static void register_event(string name, PyRT.PythonFunction pyFunc)
|
||||||
{
|
{
|
||||||
@@ -280,22 +266,22 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
if (eventInfo.Name.ToLower() == name.Replace("-", ""))
|
if (eventInfo.Name.ToLower() == name.Replace("-", ""))
|
||||||
{
|
{
|
||||||
EventObject eventObject = new EventObject();
|
PythonEventObject eventObject = new PythonEventObject();
|
||||||
EventObjects.Add(eventObject);
|
PythonEventObjects.Add(eventObject);
|
||||||
eventObject.PythonFunction = pyFunc;
|
eventObject.PythonFunction = pyFunc;
|
||||||
MethodInfo mi;
|
MethodInfo mi;
|
||||||
|
|
||||||
if (eventInfo.EventHandlerType == typeof(Action))
|
if (eventInfo.EventHandlerType == typeof(Action))
|
||||||
{
|
{
|
||||||
mi = eventObject.GetType().GetMethod(nameof(EventObject.Invoke));
|
mi = eventObject.GetType().GetMethod(nameof(PythonEventObject.Invoke));
|
||||||
}
|
}
|
||||||
else if (eventInfo.EventHandlerType == typeof(Action<EndFileEventMode>))
|
else if (eventInfo.EventHandlerType == typeof(Action<EndFileEventMode>))
|
||||||
{
|
{
|
||||||
mi = eventObject.GetType().GetMethod(nameof(EventObject.InvokeEndFileEventMode));
|
mi = eventObject.GetType().GetMethod(nameof(PythonEventObject.InvokeEndFileEventMode));
|
||||||
}
|
}
|
||||||
else if (eventInfo.EventHandlerType == typeof(Action<string[]>))
|
else if (eventInfo.EventHandlerType == typeof(Action<string[]>))
|
||||||
{
|
{
|
||||||
mi = eventObject.GetType().GetMethod(nameof(EventObject.InvokeStrings));
|
mi = eventObject.GetType().GetMethod(nameof(PythonEventObject.InvokeStrings));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
@@ -304,23 +290,19 @@ namespace mpvnet
|
|||||||
Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, eventObject, mi);
|
Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, eventObject, mi);
|
||||||
eventObject.Delegate = handler;
|
eventObject.Delegate = handler;
|
||||||
eventInfo.AddEventHandler(eventObject, handler);
|
eventInfo.AddEventHandler(eventObject, handler);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unregister_event(PyRT.PythonFunction pyFunc)
|
public static void unregister_event(PyRT.PythonFunction pyFunc)
|
||||||
{
|
{
|
||||||
foreach (var eventObjects in EventObjects)
|
foreach (var eventObjects in PythonEventObjects)
|
||||||
if (eventObjects.PythonFunction == pyFunc)
|
if (eventObjects.PythonFunction == pyFunc)
|
||||||
eventObjects.EventInfo.RemoveEventHandler(eventObjects, eventObjects.Delegate);
|
eventObjects.EventInfo.RemoveEventHandler(eventObjects, eventObjects.Delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void commandv(params string[] args)
|
public static void commandv(params string[] args)
|
||||||
{
|
|
||||||
Command(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Command(params string[] args)
|
|
||||||
{
|
{
|
||||||
if (MpvHandle == IntPtr.Zero)
|
if (MpvHandle == IntPtr.Zero)
|
||||||
return;
|
return;
|
||||||
@@ -338,7 +320,7 @@ namespace mpvnet
|
|||||||
Marshal.FreeHGlobal(mainPtr);
|
Marshal.FreeHGlobal(mainPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CommandString(string command, bool throwException = true)
|
public static void command_string(string command, bool throwException = false)
|
||||||
{
|
{
|
||||||
if (MpvHandle == IntPtr.Zero)
|
if (MpvHandle == IntPtr.Zero)
|
||||||
return;
|
return;
|
||||||
@@ -349,21 +331,21 @@ namespace mpvnet
|
|||||||
throw new Exception($"{(mpv_error)err}\r\n\r\n" + command);
|
throw new Exception($"{(mpv_error)err}\r\n\r\n" + command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetStringProp(string name, string value, bool throwException = true)
|
public static void set_property_string(string name, string value, bool throwOnException = false)
|
||||||
{
|
{
|
||||||
var bytes = GetUtf8Bytes(value);
|
var bytes = GetUtf8Bytes(value);
|
||||||
int err = mpv_set_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref bytes);
|
int err = mpv_set_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref bytes);
|
||||||
|
|
||||||
if (err < 0 && throwException)
|
if (err < 0 && throwOnException)
|
||||||
throw new Exception($"{name}: {(mpv_error)err}");
|
throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetStringProp(string name)
|
public static string get_property_string(string name, bool throwOnException = false)
|
||||||
{
|
{
|
||||||
var lpBuffer = IntPtr.Zero;
|
var lpBuffer = IntPtr.Zero;
|
||||||
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref lpBuffer);
|
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref lpBuffer);
|
||||||
|
|
||||||
if (err < 0)
|
if (err < 0 && throwOnException)
|
||||||
throw new Exception($"{name}: {(mpv_error)err}");
|
throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
|
|
||||||
var ret = StringFromNativeUtf8(lpBuffer);
|
var ret = StringFromNativeUtf8(lpBuffer);
|
||||||
@@ -372,43 +354,49 @@ namespace mpvnet
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetIntProp(string name, bool throwException = true)
|
public static int get_property_int(string name, bool throwOnException = false)
|
||||||
{
|
{
|
||||||
var lpBuffer = IntPtr.Zero;
|
var lpBuffer = IntPtr.Zero;
|
||||||
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref lpBuffer);
|
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref lpBuffer);
|
||||||
|
|
||||||
if (err < 0 && throwException)
|
if (err < 0 && throwOnException)
|
||||||
throw new Exception($"{name}: {(mpv_error)err}");
|
throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
else
|
else
|
||||||
return lpBuffer.ToInt32();
|
return lpBuffer.ToInt32();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double get_property_number(string name)
|
public static double get_property_number(string name, bool throwOnException = false)
|
||||||
{
|
|
||||||
return GetDoubleProp(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double GetDoubleProp(string name, bool throwException = true)
|
|
||||||
{
|
{
|
||||||
double val = 0;
|
double val = 0;
|
||||||
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_DOUBLE, ref val);
|
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_DOUBLE, ref val);
|
||||||
|
|
||||||
if (err < 0 && throwException)
|
if (err < 0 && throwOnException)
|
||||||
throw new Exception($"{name}: {(mpv_error)err}");
|
throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
else
|
else
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetIntProp(string name, int value)
|
public static bool get_property_bool(string name, bool throwOnException = false)
|
||||||
|
{
|
||||||
|
var lpBuffer = IntPtr.Zero;
|
||||||
|
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_FLAG, ref lpBuffer);
|
||||||
|
|
||||||
|
if (err < 0 && throwOnException)
|
||||||
|
throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
|
else
|
||||||
|
return lpBuffer.ToInt32() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set_property_int(string name, int value, bool throwOnException = false)
|
||||||
{
|
{
|
||||||
Int64 val = value;
|
Int64 val = value;
|
||||||
int err = mpv_set_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref val);
|
int err = mpv_set_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref val);
|
||||||
|
|
||||||
if (err < 0)
|
if (err < 0 && throwOnException)
|
||||||
throw new Exception($"{name}: {(mpv_error)err}");
|
throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ObserveBoolProp(string name, Action<bool> action)
|
public static void observe_property_bool(string name, Action<bool> action)
|
||||||
{
|
{
|
||||||
int err = mpv_observe_property(MpvHandle, (ulong)action.GetHashCode(), name, mpv_format.MPV_FORMAT_FLAG);
|
int err = mpv_observe_property(MpvHandle, (ulong)action.GetHashCode(), name, mpv_format.MPV_FORMAT_FLAG);
|
||||||
|
|
||||||
@@ -418,7 +406,7 @@ namespace mpvnet
|
|||||||
BoolPropChangeActions.Add(new KeyValuePair<string, Action<bool>>(name, action));
|
BoolPropChangeActions.Add(new KeyValuePair<string, Action<bool>>(name, action));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UnobserveBoolProp(string name, Action<bool> action)
|
public static void unobserve_property_bool(string name, Action<bool> action)
|
||||||
{
|
{
|
||||||
foreach (var i in BoolPropChangeActions.ToArray())
|
foreach (var i in BoolPropChangeActions.ToArray())
|
||||||
if (i.Value == action)
|
if (i.Value == action)
|
||||||
@@ -430,15 +418,15 @@ namespace mpvnet
|
|||||||
throw new Exception($"{name}: {(mpv_error)err}");
|
throw new Exception($"{name}: {(mpv_error)err}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ProcessCommandLine()
|
protected static void ProcessCommandLine()
|
||||||
{
|
{
|
||||||
var args = Environment.GetCommandLineArgs().Skip(1);
|
var args = Environment.GetCommandLineArgs().Skip(1);
|
||||||
|
|
||||||
foreach (string i in args)
|
foreach (string i in args)
|
||||||
if (!i.StartsWith("--") && File.Exists(i))
|
if (!i.StartsWith("--") && File.Exists(i))
|
||||||
mp.Command("loadfile", i, "append");
|
mp.commandv("loadfile", i, "append");
|
||||||
|
|
||||||
mp.SetStringProp("playlist-pos", "0", false);
|
mp.set_property_string("playlist-pos", "0");
|
||||||
|
|
||||||
foreach (string i in args)
|
foreach (string i in args)
|
||||||
{
|
{
|
||||||
@@ -448,25 +436,25 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
string left = i.Substring(2, i.IndexOf("=") - 2);
|
string left = i.Substring(2, i.IndexOf("=") - 2);
|
||||||
string right = i.Substring(left.Length + 3);
|
string right = i.Substring(left.Length + 3);
|
||||||
mp.SetStringProp(left, right);
|
mp.set_property_string(left, right);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mp.SetStringProp(i.Substring(2), "yes");
|
mp.set_property_string(i.Substring(2), "yes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadFiles(string[] files)
|
public static void LoadFiles(string[] files)
|
||||||
{
|
{
|
||||||
int count = mp.GetIntProp("playlist-count");
|
int count = mp.get_property_int("playlist-count");
|
||||||
|
|
||||||
foreach (string file in files)
|
foreach (string file in files)
|
||||||
mp.Command("loadfile", file, "append");
|
mp.commandv("loadfile", file, "append");
|
||||||
|
|
||||||
mp.SetIntProp("playlist-pos", count);
|
mp.set_property_int("playlist-pos", count);
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
mp.Command("playlist-remove", "0");
|
mp.commandv("playlist-remove", "0");
|
||||||
|
|
||||||
mp.LoadFolder();
|
mp.LoadFolder();
|
||||||
}
|
}
|
||||||
@@ -478,10 +466,10 @@ namespace mpvnet
|
|||||||
if (WasFolderLoaded)
|
if (WasFolderLoaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (GetIntProp("playlist-count") == 1)
|
if (get_property_int("playlist-count") == 1)
|
||||||
{
|
{
|
||||||
string[] types = "264 265 3gp aac ac3 avc avi avs bmp divx dts dtshd dtshr dtsma eac3 evo flac flv h264 h265 hevc hvc jpg jpeg m2t m2ts m2v m4a m4v mka mkv mlp mov mp2 mp3 mp4 mpa mpeg mpg mpv mts ogg ogm opus pcm png pva raw rmvb thd thd+ac3 true-hd truehd ts vdr vob vpy w64 wav webm wmv y4m".Split(' ');
|
string[] types = "264 265 3gp aac ac3 avc avi avs bmp divx dts dtshd dtshr dtsma eac3 evo flac flv h264 h265 hevc hvc jpg jpeg m2t m2ts m2v m4a m4v mka mkv mlp mov mp2 mp3 mp4 mpa mpeg mpg mpv mts ogg ogm opus pcm png pva raw rmvb thd thd+ac3 true-hd truehd ts vdr vob vpy w64 wav webm wmv y4m".Split(' ');
|
||||||
string path = GetStringProp("path");
|
string path = get_property_string("path");
|
||||||
List<string> files = Directory.GetFiles(Path.GetDirectoryName(path)).ToList();
|
List<string> files = Directory.GetFiles(Path.GetDirectoryName(path)).ToList();
|
||||||
files = files.Where((file) => types.Contains(file.Ext())).ToList();
|
files = files.Where((file) => types.Contains(file.Ext())).ToList();
|
||||||
files.Sort(new StringLogicalComparer());
|
files.Sort(new StringLogicalComparer());
|
||||||
@@ -489,10 +477,10 @@ namespace mpvnet
|
|||||||
files.Remove(path);
|
files.Remove(path);
|
||||||
|
|
||||||
foreach (string i in files)
|
foreach (string i in files)
|
||||||
Command("loadfile", i, "append");
|
commandv("loadfile", i, "append");
|
||||||
|
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
Command("playlist-move", "0", (index + 1).ToString());
|
commandv("playlist-move", "0", (index + 1).ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
WasFolderLoaded = true;
|
WasFolderLoaded = true;
|
||||||
|
|||||||
@@ -122,6 +122,9 @@
|
|||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.1.0\lib\net4\System.Management.Automation.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -132,7 +135,13 @@
|
|||||||
<Compile Include="Menu.cs">
|
<Compile Include="Menu.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="PyScript.cs" />
|
<Compile Include="Properties\Resources.Designer.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="PowerShellScript.cs" />
|
||||||
|
<Compile Include="PythonScript.cs" />
|
||||||
<Compile Include="StringExtensions.cs" />
|
<Compile Include="StringExtensions.cs" />
|
||||||
<Compile Include="libmpv.cs" />
|
<Compile Include="libmpv.cs" />
|
||||||
<Compile Include="MainForm.cs">
|
<Compile Include="MainForm.cs">
|
||||||
@@ -155,15 +164,11 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
<EmbeddedResource Include="Properties\Resources.resx">
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
</Compile>
|
|
||||||
<None Include="app.manifest" />
|
<None Include="app.manifest" />
|
||||||
|
<None Include="packages.config" />
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
@@ -173,6 +178,7 @@
|
|||||||
<DependentUpon>Settings.settings</DependentUpon>
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Content Include="Resources\mpv.conf.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
@@ -180,7 +186,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="mpv.ico" />
|
<Content Include="mpv.ico" />
|
||||||
<Content Include="screenshot.jpg" />
|
<Content Include="screenshot.jpg" />
|
||||||
<None Include="Resources\input_conf.txt" />
|
<Content Include="Resources\input.conf.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
|||||||
4
mpv.net/packages.config
Normal file
4
mpv.net/packages.config
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="Microsoft.PowerShell.5.ReferenceAssemblies" version="1.1.0" targetFramework="net472" />
|
||||||
|
</packages>
|
||||||
@@ -3,10 +3,8 @@ $exePath = $scriptDir + "\mpv.net\bin\Debug\mpvnet.exe"
|
|||||||
$version = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath).FileVersion
|
$version = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath).FileVersion
|
||||||
$desktopDir = [Environment]::GetFolderPath("Desktop")
|
$desktopDir = [Environment]::GetFolderPath("Desktop")
|
||||||
$targetDir = $desktopDir + "\mpv.net-" + $version
|
$targetDir = $desktopDir + "\mpv.net-" + $version
|
||||||
if (Test-Path $targetDir) { rd $targetDir -recurse }
|
|
||||||
Copy-Item $scriptDir\mpv.net\bin\Debug $targetDir -recurse
|
Copy-Item $scriptDir\mpv.net\bin\Debug $targetDir -recurse
|
||||||
$addonDir = $targetDir + "\Addons"
|
copy-item $scriptDir\README.md $targetDir\README.md
|
||||||
Remove-Item $addonDir -Recurse -Include *mpvnet.exe, *mpvnet.exe.config, *mpvnet.pdb
|
|
||||||
$7zPath = "C:\Program Files\7-Zip\7z.exe"
|
$7zPath = "C:\Program Files\7-Zip\7z.exe"
|
||||||
$args = "a -t7z -mx9 $targetDir.7z -r $targetDir\*"
|
$args = "a -t7z -mx9 $targetDir.7z -r $targetDir\*"
|
||||||
Start-Process -FilePath $7zPath -ArgumentList $args
|
Start-Process -FilePath $7zPath -ArgumentList $args
|
||||||
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
|
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 130 KiB |
Reference in New Issue
Block a user