This commit is contained in:
Frank Skare
2019-03-14 05:19:57 +01:00
parent a392c2c6da
commit 303355ce63
20 changed files with 242 additions and 22610 deletions

View File

@@ -11,7 +11,7 @@ Public Class CSScriptAddon
Implements IAddon
Sub New()
Dim scriptDir = mpv.mpvConfFolderPath + "scripts"
Dim scriptDir = mp.mpvConfFolderPath + "scripts"
If Not Directory.Exists(scriptDir) Then Return
Dim csFiles = Directory.GetFiles(scriptDir, "*.cs")
If csFiles.Count = 0 Then Return

View File

@@ -52,11 +52,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>.\CSScriptLibrary.dll</HintPath>
</Reference>
<Reference Include="mpvnet, Version=0.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\mpv.net\bin\Debug\mpvnet.exe</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Data" />
@@ -117,5 +112,12 @@
<ItemGroup>
<Content Include="CSScriptLibrary.dll" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\mpv.net\mpv.net.csproj">
<Project>{1751f378-8edf-4b62-be6d-304c7c287089}</Project>
<Name>mpv.net</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project>

View File

@@ -8,11 +8,11 @@ Imports System.Runtime.InteropServices
' Review the values of the assembly attributes
<Assembly: AssemblyTitle("PowerShellAddon")>
<Assembly: AssemblyTitle("CSScriptAddon")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("PowerShellAddon")>
<Assembly: AssemblyCopyright("Copyright © 2017")>
<Assembly: AssemblyProduct("CSScriptAddon")>
<Assembly: AssemblyCopyright("Copyright © 2019")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>

View File

@@ -50,8 +50,9 @@ class Script
### Changes
### 1.?
### 1.1
- added support for Python scripting via IronPython
- show tracks and show playlist didn't work because the duration wasn't defined in the key bindings
### 1.0

View File

@@ -14,8 +14,8 @@ namespace RatingAddon
public RatingAddon()
{
mpv.ClientMessage += mpv_ClientMessage;
mpv.Shutdown += mpv_Shutdown;
mp.ClientMessage += mpv_ClientMessage;
mp.Shutdown += mpv_Shutdown;
}
private void mpv_Shutdown()
@@ -51,8 +51,8 @@ namespace RatingAddon
if (args?.Length != 2 || args[0] != "rate-file" || ! int.TryParse(args[1], out rating))
return;
Dic[mpv.GetStringProp("path")] = rating;
mpv.Command("show-text", $"Rating: {rating}");
Dic[mp.GetStringProp("path")] = rating;
mp.Command("show-text", $"Rating: {rating}");
}
}
}

View File

@@ -85,6 +85,7 @@
<ProjectReference Include="..\mpv.net\mpv.net.csproj">
<Project>{1751f378-8edf-4b62-be6d-304c7c287089}</Project>
<Name>mpv.net</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@@ -28,7 +28,7 @@ namespace mpvnet
foreach (string i in Directory.GetDirectories(dir))
catalog.Catalogs.Add(new DirectoryCatalog(i, "*Addon.dll"));
dir = mpv.mpvConfFolderPath + "\\Addons";
dir = mp.mpvConfFolderPath + "\\Addons";
if (Directory.Exists(dir))
foreach (string i in Directory.GetDirectories(dir))

View File

@@ -50,41 +50,41 @@ namespace mpvnet
d.Filter = Misc.GetFilter(Misc.FileTypes);
if (d.ShowDialog() == DialogResult.OK)
mpv.LoadFiles(d.FileNames);
mp.LoadFiles(d.FileNames);
}
}));
}
public static void open_config_folder(string[] args)
{
Process.Start(mpv.mpvConfFolderPath);
Process.Start(mp.mpvConfFolderPath);
}
public static void show_keys(string[] args)
{
Process.Start(mpv.InputConfPath);
Process.Start(mp.InputConfPath);
}
private static void CreateMpvConf()
{
if (!File.Exists(mpv.mpvConfPath))
if (!File.Exists(mp.mpvConfPath))
{
if (!Directory.Exists(mpv.mpvConfFolderPath))
Directory.CreateDirectory(mpv.mpvConfFolderPath);
if (!Directory.Exists(mp.mpvConfFolderPath))
Directory.CreateDirectory(mp.mpvConfFolderPath);
File.WriteAllText(mpv.mpvConfPath, "# https://mpv.io/manual/master/#configuration-files");
File.WriteAllText(mp.mpvConfPath, "# https://mpv.io/manual/master/#configuration-files");
}
}
public static void show_prefs(string[] args)
{
CreateMpvConf();
Process.Start(mpv.mpvConfPath);
Process.Start(mp.mpvConfPath);
}
public static void history(string[] args)
{
var fp = mpv.mpvConfFolderPath + "history.txt";
var fp = mp.mpvConfFolderPath + "history.txt";
if (File.Exists(fp))
Process.Start(fp);
@@ -103,7 +103,7 @@ namespace mpvnet
CreateMpvConf();
bool changed = false;
string fp = mpv.mpvConfPath;
string fp = mp.mpvConfPath;
var confLines = File.ReadAllLines(fp);
for (int i = 0; i < confLines.Length; i++)
@@ -130,21 +130,21 @@ namespace mpvnet
public static void show_info(string[] args)
{
var fi = new FileInfo(mpv.GetStringProp("path"));
var fi = new FileInfo(mp.GetStringProp("path"));
using (var mi = new MediaInfo(fi.FullName))
{
var w = mi.GetInfo(MediaInfoStreamKind.Video, "Width");
var h = mi.GetInfo(MediaInfoStreamKind.Video, "Height");
var pos = TimeSpan.FromSeconds(mpv.GetIntProp("time-pos"));
var dur = TimeSpan.FromSeconds(mpv.GetIntProp("duration"));
var pos = TimeSpan.FromSeconds(mp.GetIntProp("time-pos"));
var dur = TimeSpan.FromSeconds(mp.GetIntProp("duration"));
string mibr = mi.GetInfo(MediaInfoStreamKind.Video, "BitRate");
if (mibr == "")
mibr = "0";
var br = Convert.ToInt32(mibr) / 1000.0 / 1000.0;
var vf = mpv.GetStringProp("video-format").ToUpper();
var vf = mp.GetStringProp("video-format").ToUpper();
var fn = fi.Name;
if (fn.Length > 60)
@@ -158,7 +158,7 @@ namespace mpvnet
((int)(fi.Length / 1024 / 1024)).ToString() +
$" MB - {w} x {h}\n{vf} - {br.ToString("f1")} Mb/s" + "\n" + fn;
mpv.Command("show-text", info, "5000");
mp.Command("show-text", info, "5000");
string FormatTime(double value) => ((int)(Math.Floor(value))).ToString("00");
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -30,7 +30,7 @@ namespace mpvnet
SetFormPosSize();
Instance = this;
Hwnd = Handle;
ChangeFullscreen((mpv.mpvConv.ContainsKey("fullscreen") && mpv.mpvConv["fullscreen"] == "yes") || (mpv.mpvConv.ContainsKey("fs") && mpv.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;
@@ -44,15 +44,15 @@ namespace mpvnet
public void BuildMenu()
{
if (!File.Exists(mpv.InputConfPath))
if (!File.Exists(mp.InputConfPath))
{
if (!Directory.Exists(mpv.mpvConfFolderPath))
Directory.CreateDirectory(mpv.mpvConfFolderPath);
if (!Directory.Exists(mp.mpvConfFolderPath))
Directory.CreateDirectory(mp.mpvConfFolderPath);
File.WriteAllText(mpv.InputConfPath, Properties.Resources.input_conf);
File.WriteAllText(mp.InputConfPath, Properties.Resources.input_conf);
}
foreach (var i in File.ReadAllText(mpv.InputConfPath).SplitLinesNoEmpty())
foreach (var i in File.ReadAllText(mp.InputConfPath).SplitLinesNoEmpty())
{
if (!i.Contains("#menu:"))
continue;
@@ -73,7 +73,7 @@ namespace mpvnet
var menuItem = CMS.Add(path, () => {
try
{
mpv.CommandString(cmd, false);
mp.CommandString(cmd, false);
}
catch (Exception e)
{
@@ -95,9 +95,9 @@ namespace mpvnet
private void mpv_PlaybackRestart()
{
var fn = mpv.GetStringProp("filename");
var fn = mp.GetStringProp("filename");
BeginInvoke(new Action(() => { Text = fn + " - mpv.net " + Application.ProductVersion; }));
var fp = mpv.mpvConfFolderPath + "history.txt";
var fp = mp.mpvConfFolderPath + "history.txt";
if (LastHistory != fn && File.Exists(fp))
{
@@ -166,19 +166,19 @@ namespace mpvnet
case 0x0100: // WM_KEYDOWN
case 0x0101: // WM_KEYUP
case 0x020A: // WM_MOUSEWHEEL
if (mpv.MpvWindowHandle != IntPtr.Zero)
Native.SendMessage(mpv.MpvWindowHandle, m.Msg, m.WParam, m.LParam);
if (mp.MpvWindowHandle != IntPtr.Zero)
Native.SendMessage(mp.MpvWindowHandle, m.Msg, m.WParam, m.LParam);
break;
case 0x203: // Native.WM.LBUTTONDBLCLK
if (!IsMouseInOSC())
mpv.CommandString("cycle fullscreen");
mp.CommandString("cycle fullscreen");
break;
case 0x0214: // WM_SIZING
var rc = Marshal.PtrToStructure<Native.RECT>(m.LParam);
var r = rc;
NativeHelp.SubtractWindowBorders(Handle, ref r);
int c_w = r.Right - r.Left, c_h = r.Bottom - r.Top;
float aspect = mpv.VideoSize.Width / (float)mpv.VideoSize.Height;
float aspect = mp.VideoSize.Width / (float)mp.VideoSize.Height;
int d_w = (int)(c_h * aspect - c_w);
int d_h = (int)(c_w / aspect - c_h);
int[] d_corners = { d_w, d_h, -d_w, -d_h };
@@ -198,10 +198,10 @@ namespace mpvnet
void SetFormPosSize()
{
if (IsFullscreen || mpv.VideoSize.Width == 0) return;
if (IsFullscreen || mp.VideoSize.Width == 0) return;
var wa = Screen.GetWorkingArea(this);
int h = (int)(wa.Height * 0.6);
int w = (int)(h * mpv.VideoSize.Width / (float)mpv.VideoSize.Height);
int w = (int)(h * mp.VideoSize.Width / (float)mp.VideoSize.Height);
Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
var r = new Native.RECT(new Rectangle(0, 0, w, h));
NativeHelp.AddWindowBorders(Handle, ref r);
@@ -227,7 +227,7 @@ namespace mpvnet
base.OnDragDrop(e);
if (e.Data.GetDataPresent(DataFormats.FileDrop))
mpv.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as String[]);
mp.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as String[]);
}
protected override void OnMouseDown(MouseEventArgs e)
@@ -249,7 +249,7 @@ namespace mpvnet
var p2 = PointToScreen(e.Location);
if (Math.Abs(p1.X - p2.X) < 10 && Math.Abs(p1.Y - p2.Y) < 10)
mpv.Command("quit");
mp.Command("quit");
}
protected override void OnMouseMove(MouseEventArgs e)
@@ -257,7 +257,7 @@ namespace mpvnet
base.OnMouseMove(e);
// send mouse command to make OSC show
mpv.CommandString($"mouse {e.X} {e.Y}");
mp.CommandString($"mouse {e.X} {e.Y}");
if (CursorHelp.IsPosDifferent(LastCursorPosChanged))
CursorHelp.Show();
@@ -267,7 +267,7 @@ namespace mpvnet
{
base.OnFormClosed(e);
IsCloseRequired = false;
mpv.Command("quit");
mp.Command("quit");
}
bool IsMouseInOSC()
@@ -292,11 +292,11 @@ namespace mpvnet
private void MainForm_Load(object sender, EventArgs ea)
{
mpv.Init();
mpv.ObserveBoolProp("fullscreen", MpvChangeFullscreen);
mpv.Shutdown += Mpv_AfterShutdown;
mpv.VideoSizeChanged += Mpv_VideoSizeChanged;
mpv.PlaybackRestart += mpv_PlaybackRestart;
mp.Init();
mp.ObserveBoolProp("fullscreen", MpvChangeFullscreen);
mp.Shutdown += Mpv_AfterShutdown;
mp.VideoSizeChanged += Mpv_VideoSizeChanged;
mp.PlaybackRestart += mpv_PlaybackRestart;
}
}
}

View File

@@ -1,14 +1,8 @@
using System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using static mpvnet.StaticUsing;
namespace mpvnet
{
public class Misc
@@ -49,28 +43,4 @@ namespace mpvnet
return MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
}
}
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());
}
}
}
}

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
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

33
mpv.net/PyScript.cs Normal file
View File

@@ -0,0 +1,33 @@
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());
}
}
}
}

View File

@@ -29,6 +29,9 @@ namespace mpvnet
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int mpv_get_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref IntPtr data);
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int mpv_get_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref double data);
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int mpv_set_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref byte[] data);
@@ -102,7 +105,8 @@ namespace mpvnet
MPV_EVENT_PLAYBACK_RESTART = 21,
MPV_EVENT_PROPERTY_CHANGE = 22,
MPV_EVENT_CHAPTER_CHANGE = 23,
MPV_EVENT_QUEUE_OVERFLOW = 24
MPV_EVENT_QUEUE_OVERFLOW = 24,
MPV_EVENT_HOOK = 25
}
public enum mpv_format
@@ -168,7 +172,6 @@ namespace mpvnet
[StructLayout(LayoutKind.Sequential)]
public struct mpv_event_property
{
[MarshalAs(UnmanagedType.LPUTF8Str)]
public string name;
public mpv_format format;
public IntPtr data;

View File

@@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
@@ -13,36 +14,43 @@ using static mpvnet.libmpv;
using static mpvnet.Native;
using static mpvnet.StaticUsing;
using PyRT = IronPython.Runtime;
namespace mpvnet
{
public delegate void MpvBoolPropChangeHandler(string propName, bool value);
public class mpv
public class mp
{
public static event Action Shutdown;
public static event Action LogMessage;
public static event Action GetPropertyReply;
public static event Action<string[]> ClientMessage;
public static event Action PlaybackRestart;
public static event Action VideoSizeChanged;
public static event Action<EndFileEventMode> EndFile;
public static event Action SetPropertyReply;
public static event Action CommandReply;
public static event Action StartFile;
public static event Action FileLoaded;
public static event Action TracksChanged;
public static event Action TrackSwitched;
public static event Action Idle;
public static event Action Pause;
public static event Action Unpause;
public static event Action Tick;
public static event Action ScriptInputDispatch;
public static event Action VideoReconfig;
public static event Action AudioReconfig;
public static event Action MetadataUpdate;
public static event Action Seek;
public static event Action ChapterChange;
public static event Action QueueOverflow;
// Lua/JS evens libmpv events
// MPV_EVENT_NONE
public static event Action Shutdown; // shutdown MPV_EVENT_SHUTDOWN
public static event Action LogMessage; // log-message MPV_EVENT_LOG_MESSAGE
public static event Action GetPropertyReply; // get-property-reply MPV_EVENT_GET_PROPERTY_REPLY
public static event Action SetPropertyReply; // set-property-reply MPV_EVENT_SET_PROPERTY_REPLY
public static event Action CommandReply; // command-reply MPV_EVENT_COMMAND_REPLY
public static event Action StartFile; // start-file MPV_EVENT_START_FILE
public static event Action<EndFileEventMode> EndFile; // end-file MPV_EVENT_END_FILE
public static event Action FileLoaded; // file-loaded MPV_EVENT_FILE_LOADED
public static event Action TracksChanged; // MPV_EVENT_TRACKS_CHANGED
public static event Action TrackSwitched; // MPV_EVENT_TRACK_SWITCHED
public static event Action Idle; // idle MPV_EVENT_IDLE
public static event Action Pause; // MPV_EVENT_PAUSE
public static event Action Unpause; // MPV_EVENT_UNPAUSE
public static event Action Tick; // tick MPV_EVENT_TICK
public static event Action ScriptInputDispatch; // MPV_EVENT_SCRIPT_INPUT_DISPATCH
public static event Action<string[]> ClientMessage; // client-message MPV_EVENT_CLIENT_MESSAGE
public static event Action VideoReconfig; // video-reconfig MPV_EVENT_VIDEO_RECONFIG
public static event Action AudioReconfig; // audio-reconfig MPV_EVENT_AUDIO_RECONFIG
public static event Action MetadataUpdate; // MPV_EVENT_METADATA_UPDATE
public static event Action Seek; // seek MPV_EVENT_SEEK
public static event Action PlaybackRestart; // playback-restart MPV_EVENT_PLAYBACK_RESTART
// MPV_EVENT_PROPERTY_CHANGE
public static event Action ChapterChange; // MPV_EVENT_CHAPTER_CHANGE
public static event Action QueueOverflow; // MPV_EVENT_QUEUE_OVERFLOW
public static event Action Hook; // MPV_EVENT_HOOK
public static IntPtr MpvHandle;
public static IntPtr MpvWindowHandle;
@@ -104,24 +112,19 @@ namespace mpvnet
public static void LoadScripts()
{
string[] extensions = { ".lua", ".js" };
string[] scripts = Directory.GetFiles(Application.StartupPath + "\\Scripts");
string[] jsLua = { ".lua", ".js" };
string[] startupScripts = Directory.GetFiles(Application.StartupPath + "\\Scripts");
foreach (var scriptPath in scripts)
{
string ext = Path.GetExtension(scriptPath);
foreach (var scriptPath in startupScripts)
if (jsLua.Contains(Path.GetExtension(scriptPath).ToLower()))
mp.Command("load-script", $"{scriptPath}");
if (extensions.Contains(ext.ToLower()))
mpv.Command("load-script", $"{scriptPath}");
}
foreach (var scriptPath in scripts)
{
string ext = Path.GetExtension(scriptPath);
if (ext == ".py")
foreach (var scriptPath in startupScripts)
if (Path.GetExtension(scriptPath) == ".py")
PyScripts.Add(new PyScript(File.ReadAllText(scriptPath)));
}
foreach(var scriptPath in Directory.GetFiles(mp.mpvConfFolderPath + "scripts", "*.py"))
PyScripts.Add(new PyScript(File.ReadAllText(scriptPath)));
}
public static void EventLoop()
@@ -240,10 +243,83 @@ namespace mpvnet
case mpv_event_id.MPV_EVENT_QUEUE_OVERFLOW:
QueueOverflow?.Invoke();
break;
case mpv_event_id.MPV_EVENT_HOOK:
Hook?.Invoke();
break;
}
}
}
public class EventObject
{
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)
{
foreach (var eventInfo in typeof(mp).GetEvents())
{
if (eventInfo.Name.ToLower() == name.Replace("-", ""))
{
EventObject eventObject = new EventObject();
EventObjects.Add(eventObject);
eventObject.PythonFunction = pyFunc;
MethodInfo mi;
if (eventInfo.EventHandlerType == typeof(Action))
{
mi = eventObject.GetType().GetMethod(nameof(EventObject.Invoke));
}
else if (eventInfo.EventHandlerType == typeof(Action<EndFileEventMode>))
{
mi = eventObject.GetType().GetMethod(nameof(EventObject.InvokeEndFileEventMode));
}
else if (eventInfo.EventHandlerType == typeof(Action<string[]>))
{
mi = eventObject.GetType().GetMethod(nameof(EventObject.InvokeStrings));
}
else
throw new Exception();
eventObject.EventInfo = eventInfo;
Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, eventObject, mi);
eventObject.Delegate = handler;
eventInfo.AddEventHandler(eventObject, handler);
}
}
}
public static void unregister_event(PyRT.PythonFunction pyFunc)
{
foreach (var eventObjects in EventObjects)
if (eventObjects.PythonFunction == pyFunc)
eventObjects.EventInfo.RemoveEventHandler(eventObjects, eventObjects.Delegate);
}
public static void commandv(params string[] args)
{
Command(args);
}
public static void Command(params string[] args)
{
if (MpvHandle == IntPtr.Zero)
@@ -307,6 +383,22 @@ namespace mpvnet
return lpBuffer.ToInt32();
}
public static double get_property_number(string name)
{
return GetDoubleProp(name);
}
public static double GetDoubleProp(string name, bool throwException = true)
{
double val = 0;
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_DOUBLE, ref val);
if (err < 0 && throwException)
throw new Exception($"{name}: {(mpv_error)err}");
else
return val;
}
public static void SetIntProp(string name, int value)
{
Int64 val = value;
@@ -344,9 +436,9 @@ namespace mpvnet
foreach (string i in args)
if (!i.StartsWith("--") && File.Exists(i))
mpv.Command("loadfile", i, "append");
mp.Command("loadfile", i, "append");
mpv.SetStringProp("playlist-pos", "0", false);
mp.SetStringProp("playlist-pos", "0", false);
foreach (string i in args)
{
@@ -356,27 +448,27 @@ namespace mpvnet
{
string left = i.Substring(2, i.IndexOf("=") - 2);
string right = i.Substring(left.Length + 3);
mpv.SetStringProp(left, right);
mp.SetStringProp(left, right);
}
else
mpv.SetStringProp(i.Substring(2), "yes");
mp.SetStringProp(i.Substring(2), "yes");
}
}
}
public static void LoadFiles(string[] files)
{
int count = mpv.GetIntProp("playlist-count");
int count = mp.GetIntProp("playlist-count");
foreach (string file in files)
mpv.Command("loadfile", file, "append");
mp.Command("loadfile", file, "append");
mpv.SetIntProp("playlist-pos", count);
mp.SetIntProp("playlist-pos", count);
for (int i = 0; i < count; i++)
mpv.Command("playlist-remove", "0");
mp.Command("playlist-remove", "0");
mpv.LoadFolder();
mp.LoadFolder();
}
private static bool WasFolderLoaded;

View File

@@ -132,6 +132,7 @@
<Compile Include="Menu.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="PyScript.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="libmpv.cs" />
<Compile Include="MainForm.cs">
@@ -141,7 +142,7 @@
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Misc.cs" />
<Compile Include="mpv.cs" />
<Compile Include="mp.cs" />
<Compile Include="Command.cs" />
<Compile Include="Native.cs" />
<Compile Include="NativeHelp.cs" />

View File

@@ -9,4 +9,4 @@ $addonDir = $targetDir + "\Addons"
Remove-Item $addonDir -Recurse -Include *mpvnet.exe, *mpvnet.exe.config, *mpvnet.pdb
$7zPath = "C:\Program Files\7-Zip\7z.exe"
$args = "a -t7z -mx9 $targetDir.7z -r $targetDir\*"
Start-Process -FilePath $7zPath -ArgumentList $args
#Start-Process -FilePath $7zPath -ArgumentList $args