scripting docs
This commit is contained in:
72
Manual.md
72
Manual.md
@@ -16,7 +16,8 @@ Table of contents
|
|||||||
+ [Play with mpv](#play-with-mpv)
|
+ [Play with mpv](#play-with-mpv)
|
||||||
+ [External Application Button](#external-application-button)
|
+ [External Application Button](#external-application-button)
|
||||||
+ [Open with++](#open-with)
|
+ [Open with++](#open-with)
|
||||||
+ [MediaInfo.NET](#mediainfonet)
|
+ [MediaInfo.NET](#mediainfonet)
|
||||||
|
* [Scripting](#scripting)
|
||||||
* [Extensions](#extensions)
|
* [Extensions](#extensions)
|
||||||
* [Color Theme](#color-theme)
|
* [Color Theme](#color-theme)
|
||||||
* [Hidden and secret features](#hidden-and-secret-features)
|
* [Hidden and secret features](#hidden-and-secret-features)
|
||||||
@@ -224,9 +225,9 @@ Terminal
|
|||||||
|
|
||||||
When mpv.net is started from a terminal it will output status, error and debug messages to the terminal and accept input keys from the terminal.
|
When mpv.net is started from a terminal it will output status, error and debug messages to the terminal and accept input keys from the terminal.
|
||||||
|
|
||||||
In the context menu under 'Tools > Setup' a button can be found to add mpv.net to the path environment variable, mpv.net is than available in the terminal via mpvnet command.
|
In the context menu under 'Tools > Setup' a button can be found to add mpv.net to the path environment variable.
|
||||||
|
|
||||||
JavaScript and Lua scripts must be debugged with the terminal as there is no debugger support available.
|
A common task for the terminal is debugging scripts.
|
||||||
|
|
||||||
|
|
||||||
External Tools
|
External Tools
|
||||||
@@ -276,9 +277,74 @@ If the path has spaces then it must be enclosed in quotes and then double backsl
|
|||||||
`_ run "D:/Soft ware/MediaInfoNET.exe" "${path}" #menu: Tools > Open file with MediaInfo.NET`
|
`_ run "D:/Soft ware/MediaInfoNET.exe" "${path}" #menu: Tools > Open file with MediaInfo.NET`
|
||||||
|
|
||||||
|
|
||||||
|
Scripting
|
||||||
|
---------
|
||||||
|
|
||||||
|
There is no debugger support available for the scripting hosts, mpv.net can be started from a terminal,
|
||||||
|
script errors and debug messages are printed then on the terminal.
|
||||||
|
|
||||||
|
|
||||||
|
#### Lua
|
||||||
|
|
||||||
|
File Type: `lua`
|
||||||
|
|
||||||
|
Location: `<config folder>\scripts`
|
||||||
|
|
||||||
|
Lua and JavaScript scripts are loaded before the first media file loads.
|
||||||
|
|
||||||
|
[mpv Lua documentation](https://mpv.io/manual/master/#lua-scripting)
|
||||||
|
|
||||||
|
[mpv user scripts](https://github.com/mpv-player/mpv/wiki/User-Scripts)
|
||||||
|
|
||||||
|
|
||||||
|
#### JavaScript
|
||||||
|
|
||||||
|
File Type: `js`
|
||||||
|
|
||||||
|
Location: `<config folder>\scripts`
|
||||||
|
|
||||||
|
Lua and JavaScript scripts are loaded before the first media file loads.
|
||||||
|
|
||||||
|
[mpv JavaScript documentation](https://mpv.io/manual/master/#javascript)
|
||||||
|
|
||||||
|
[mpv user scripts](https://github.com/mpv-player/mpv/wiki/User-Scripts)
|
||||||
|
|
||||||
|
|
||||||
|
#### C#
|
||||||
|
|
||||||
|
File Type: `cs`
|
||||||
|
|
||||||
|
Location: `<config folder>\scripts-cs`
|
||||||
|
|
||||||
|
C# scripting in mpv.net is implemented with a C# [extension](Extensions) and [CS-Script](https://www.cs-script.net/).
|
||||||
|
|
||||||
|
mpv.net does not define scripting interfaces but instead exposed its complete internals, there are no compatibility guaranties.
|
||||||
|
|
||||||
|
Script code can be written within a C# [extension](Extensions), that way full code completion and debugger support is available. Once the code was developed and debugged, the code can be moved from the extension to a lightweight standalone script.
|
||||||
|
|
||||||
|
The C# scripting host is like [extensions](Extensions) not initialized before media files are loaded.
|
||||||
|
|
||||||
|
[Example Scripts](scripts/examples)
|
||||||
|
|
||||||
|
|
||||||
|
#### PowerShell
|
||||||
|
|
||||||
|
File Type: `ps1`
|
||||||
|
|
||||||
|
Location: `<config folder>\scripts-ps`
|
||||||
|
|
||||||
|
The PowerShell scripting host is like extensions not initialized before media files are loaded.
|
||||||
|
|
||||||
|
mpv.net does not define scripting interfaces but instead exposed its complete internals, there are no compatibility guaranties.
|
||||||
|
|
||||||
|
[Example Scripts](scripts/examples)
|
||||||
|
|
||||||
|
|
||||||
Extensions
|
Extensions
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
mpv.net does not define extension interfaces but instead exposed its complete internals, there are no compatibility guaranties.
|
||||||
|
|
||||||
### Walkthrough creating an extension
|
### Walkthrough creating an extension
|
||||||
|
|
||||||
- Download and install [Visual Studio Community](https://visualstudio.microsoft.com).
|
- Download and install [Visual Studio Community](https://visualstudio.microsoft.com).
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
// creates context menu items dynamically
|
// This script creates context menu items dynamically.
|
||||||
|
|
||||||
using mpvnet;
|
using mpvnet;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
// This script adds a key binding.
|
||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using mpvnet;
|
using mpvnet;
|
||||||
|
|||||||
4
scripts/examples/message-box.ps1
Normal file
4
scripts/examples/message-box.ps1
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
// This script shows a message box using the Msg class of mpv.net.
|
||||||
|
|
||||||
|
[Msg]::Show("Hello World")
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
// Draws text on screen when full screen property changes.
|
// This script observes the fullscreen property and
|
||||||
|
// draws text on screen when the property changes.
|
||||||
|
|
||||||
using mpvnet;
|
using mpvnet;
|
||||||
|
|
||||||
@@ -12,6 +13,6 @@ class Script
|
|||||||
|
|
||||||
void FullscreenChange(bool value)
|
void FullscreenChange(bool value)
|
||||||
{
|
{
|
||||||
mp.commandv("show-text", "fullscreen: " + value.ToString());
|
mp.commandv("show-text", "fullscreen: " + value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
25
scripts/examples/open-file-dialog.ps1
Normal file
25
scripts/examples/open-file-dialog.ps1
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
# Shows the Open File dialog to open a file without loading its folder into the playlist.
|
||||||
|
|
||||||
|
# In input.conf add: <key> script-message load-without-folder
|
||||||
|
|
||||||
|
$job = Register-ObjectEvent -InputObject ([mpvnet.mp]) -EventName ClientMessage -Action {
|
||||||
|
|
||||||
|
# exit if message does not equal 'load-without-folder'
|
||||||
|
if ($args.Length -ne 1 -or $args[0] -ne 'load-without-folder')
|
||||||
|
{
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
$dialog = New-Object Windows.Forms.OpenFileDialog
|
||||||
|
|
||||||
|
if ($dialog.ShowDialog() -ne "OK") {
|
||||||
|
$dialog.Dispose()
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
[mp]::Load($dialog.FileNames, $false, $false);
|
||||||
|
$dialog.Dispose()
|
||||||
|
}
|
||||||
|
|
||||||
|
$ScriptHost.RedirectEventJobStreams($job)
|
||||||
8
scripts/examples/seek.ps1
Normal file
8
scripts/examples/seek.ps1
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
# Display position in window title bar when seeking
|
||||||
|
|
||||||
|
$job = Register-ObjectEvent -InputObject ([mpvnet.mp]) -EventName Seek -Action {
|
||||||
|
[MainForm]::Instance.Text = [mp]::get_property_number("time-pos")
|
||||||
|
}
|
||||||
|
|
||||||
|
$ScriptHost.RedirectEventJobStreams($job)
|
||||||
27
scripts/examples/show-playlist.js
Normal file
27
scripts/examples/show-playlist.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
// This script shows the playlist.
|
||||||
|
|
||||||
|
function showPlaylist()
|
||||||
|
{
|
||||||
|
|
||||||
|
// set font size
|
||||||
|
mp.set_property_number("osd-font-size", 40);
|
||||||
|
|
||||||
|
// show playlist for 5 seconds
|
||||||
|
mp.command("show-text ${playlist} 5000");
|
||||||
|
|
||||||
|
// restore original font size in 6 seconds
|
||||||
|
setTimeout(resetFontSize, 6000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore original font size
|
||||||
|
function resetFontSize()
|
||||||
|
{
|
||||||
|
mp.set_property_number("osd-font-size", size);
|
||||||
|
}
|
||||||
|
|
||||||
|
// save original font size
|
||||||
|
var size = mp.get_property_number("osd-font-size");
|
||||||
|
|
||||||
|
// input.conf: key script-binding show-playlist
|
||||||
|
mp.add_key_binding(null, "show-playlist", showPlaylist);
|
||||||
Reference in New Issue
Block a user