From 14a172b78bd3eab146122fcd147ed1f1472679b9 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Wed, 22 Apr 2020 19:17:12 +0200 Subject: [PATCH] scripting docs --- Manual.md | 72 ++++++++++++++++++- .../examples/dynamic-context-menu-items.cs | 2 +- scripts/examples/key-binding.cs | 2 + scripts/examples/message-box.ps1 | 4 ++ ...n.cs => observe-property-and-draw-text.cs} | 5 +- scripts/examples/open-file-dialog.ps1 | 25 +++++++ scripts/examples/seek.ps1 | 8 +++ scripts/examples/show-playlist.js | 27 +++++++ 8 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 scripts/examples/message-box.ps1 rename scripts/examples/{observe-property-and-draw-text-on-screen.cs => observe-property-and-draw-text.cs} (53%) create mode 100644 scripts/examples/open-file-dialog.ps1 create mode 100644 scripts/examples/seek.ps1 create mode 100644 scripts/examples/show-playlist.js diff --git a/Manual.md b/Manual.md index 6185cae..e25f1e6 100644 --- a/Manual.md +++ b/Manual.md @@ -16,7 +16,8 @@ Table of contents + [Play with mpv](#play-with-mpv) + [External Application Button](#external-application-button) + [Open with++](#open-with) - + [MediaInfo.NET](#mediainfonet) + + [MediaInfo.NET](#mediainfonet) +* [Scripting](#scripting) * [Extensions](#extensions) * [Color Theme](#color-theme) * [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. -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 @@ -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` +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: `\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: `\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: `\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: `\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 ---------- +mpv.net does not define extension interfaces but instead exposed its complete internals, there are no compatibility guaranties. + ### Walkthrough creating an extension - Download and install [Visual Studio Community](https://visualstudio.microsoft.com). diff --git a/scripts/examples/dynamic-context-menu-items.cs b/scripts/examples/dynamic-context-menu-items.cs index b8dae9d..cd732a6 100644 --- a/scripts/examples/dynamic-context-menu-items.cs +++ b/scripts/examples/dynamic-context-menu-items.cs @@ -1,5 +1,5 @@ -// creates context menu items dynamically +// This script creates context menu items dynamically. using mpvnet; using System.ComponentModel; diff --git a/scripts/examples/key-binding.cs b/scripts/examples/key-binding.cs index 487fdf9..598b0c2 100644 --- a/scripts/examples/key-binding.cs +++ b/scripts/examples/key-binding.cs @@ -1,4 +1,6 @@ +// This script adds a key binding. + using System.Reflection; using mpvnet; diff --git a/scripts/examples/message-box.ps1 b/scripts/examples/message-box.ps1 new file mode 100644 index 0000000..66286f7 --- /dev/null +++ b/scripts/examples/message-box.ps1 @@ -0,0 +1,4 @@ + +// This script shows a message box using the Msg class of mpv.net. + +[Msg]::Show("Hello World") diff --git a/scripts/examples/observe-property-and-draw-text-on-screen.cs b/scripts/examples/observe-property-and-draw-text.cs similarity index 53% rename from scripts/examples/observe-property-and-draw-text-on-screen.cs rename to scripts/examples/observe-property-and-draw-text.cs index 03cc264..e7caec3 100644 --- a/scripts/examples/observe-property-and-draw-text-on-screen.cs +++ b/scripts/examples/observe-property-and-draw-text.cs @@ -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; @@ -12,6 +13,6 @@ class Script void FullscreenChange(bool value) { - mp.commandv("show-text", "fullscreen: " + value.ToString()); + mp.commandv("show-text", "fullscreen: " + value); } } diff --git a/scripts/examples/open-file-dialog.ps1 b/scripts/examples/open-file-dialog.ps1 new file mode 100644 index 0000000..a22e11a --- /dev/null +++ b/scripts/examples/open-file-dialog.ps1 @@ -0,0 +1,25 @@ + +# Shows the Open File dialog to open a file without loading its folder into the playlist. + +# In input.conf add: 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) diff --git a/scripts/examples/seek.ps1 b/scripts/examples/seek.ps1 new file mode 100644 index 0000000..290813b --- /dev/null +++ b/scripts/examples/seek.ps1 @@ -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) diff --git a/scripts/examples/show-playlist.js b/scripts/examples/show-playlist.js new file mode 100644 index 0000000..46b3d21 --- /dev/null +++ b/scripts/examples/show-playlist.js @@ -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);