This commit is contained in:
Frank Skare
2021-05-07 11:12:59 +02:00
parent b38c7cf834
commit 41a14cd3b7
10 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
// This script creates context menu items dynamically.
using mpvnet;
using System.ComponentModel;
using System.Linq;
class Script
{
MainForm MainForm;
Core core;
public Script()
{
core = Core.core;
MainForm = mpvnet.MainForm.Instance;
MainForm.ContextMenu.Opening += ContextMenu_Opening;
}
void ContextMenu_Opening(object sender, CancelEventArgs e)
{
// edit input.conf and add 'Edition' menu item there
MenuItem menuItem = MainForm.FindMenuItem("Edition");
if (menuItem == null)
return;
menuItem.DropDownItems.Clear();
var editionTracks = core.MediaTracks.Where(track => track.Type == "e");
foreach (MediaTrack track in editionTracks)
{
MenuItem mi = new MenuItem(track.Text);
mi.Action = () => { core.commandv("set", "edition", track.ID.ToString()); };
mi.Checked = core.Edition == track.ID;
menuItem.DropDownItems.Add(mi);
}
}
}

View File

@@ -0,0 +1,29 @@
// This script adds a key binding.
using System.Reflection;
using mpvnet;
class Script
{
public Script()
{
string content = "ctrl+w script-message my-message-1 my-argument-1";
string sectionName = Assembly.GetExecutingAssembly().GetName().Name;
Core core = Core.core;
core.commandv("define-section", sectionName, content, "force");
core.commandv("enable-section", sectionName);
core.ClientMessage += ClientMessage;
}
void ClientMessage(string[] args)
{
switch (args[0])
{
case "my-message-1":
Msg.Show(args[1]);
break;
}
}
}

View File

@@ -0,0 +1,21 @@
// This script observes the fullscreen property and
// draws text on screen when the property changes.
using mpvnet;
class Script
{
Core core;
public Script()
{
core = Core.core;
core.observe_property_bool("fullscreen", FullscreenChange);
}
void FullscreenChange(bool value)
{
core.commandv("show-text", "fullscreen: " + value);
}
}

View File

@@ -0,0 +1,45 @@
// Pauses playback when window is minimized and resumes afterwards.
using System;
using System.Windows.Forms;
using mpvnet;
class Script
{
MainForm Form;
Core core;
bool WasPlaying;
bool WasPaused;
public Script()
{
core = Core.core;
Form = MainForm.Instance;
Form.Resize += Form_Resize;
}
private void Form_Resize(object sender, EventArgs e)
{
if (Form.WindowState == FormWindowState.Minimized)
{
WasPlaying = !core.get_property_bool("pause");
if (WasPlaying)
{
core.set_property_bool("pause", true, true);
WasPaused = true;
}
}
else
{
if (WasPaused)
{
core.set_property_bool("pause", false, true);
WasPaused = false;
}
}
}
}

View File

@@ -0,0 +1,35 @@
// When seeking displays position and duration like so: 70:00 / 80:00
// Which is different from most players which use: 01:10:00 / 01:20:00
// In input.conf set the input command prefix no-osd infront of the seek command.
function add_zero(val)
{
val = Math.round(val);
return val > 9 ? "" + val : "0" + val;
}
function format(val)
{
var sec = Math.round(val);
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);
}
function on_seek(_)
{
pos = mp.get_property_number("time-pos");
dur = mp.get_property_number("duration");
if (pos > dur)
pos = dur;
mp.commandv("show-text", format(pos) + " / " + format(dur));
}
mp.register_event("seek", on_seek);

View File

@@ -0,0 +1,26 @@
// 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);

View File

@@ -0,0 +1,23 @@
-- https://github.com/mpv-player/mpv/blob/master/TOOLS/lua/pause-when-minimize.lua
-- This script pauses playback when minimizing the window, and resumes playback
-- if it's brought back again. If the player was already paused when minimizing,
-- then try not to mess with the pause state.
local did_minimize = false
mp.observe_property("window-minimized", "bool", function(name, value)
local pause = mp.get_property_native("pause")
if value == true then
if pause == false then
mp.set_property_native("pause", true)
did_minimize = true
end
elseif value == false then
if did_minimize and (pause == true) then
mp.set_property_native("pause", false)
end
did_minimize = false
end
end)

View File

@@ -0,0 +1,20 @@
# 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
$code = {
if ($args[0] -eq 'load-without-folder')
{
$dialog = New-Object Windows.Forms.OpenFileDialog
if ($dialog.ShowDialog() -eq 'OK')
{
$core.LoadFiles($dialog.FileNames, $false, $false);
}
$dialog.Dispose()
}
}
$mp.register_event("client-message", $code)

View File

@@ -0,0 +1,25 @@
$code = {
$isMinimized = $args[0]
$isPaused = $mp.get_property_bool('pause')
if ($isMinimized)
{
if (-not $isPaused)
{
$mp.set_property_bool('pause', $true)
$script:wasPaused = $true
}
}
else
{
if ($script:wasPaused -and $isPaused)
{
$mp.set_property_bool('pause', $false)
}
$script:wasPaused = $false
}
}
$mp.observe_property('window-minimized', 'bool', $code)

View File

@@ -0,0 +1,14 @@
# Shows the current file in File Explorer
# In input.conf add: <key> script-message show-in-file-explorer
$code = {
if ($args[0] -eq 'show-in-file-explorer')
{
# probably works only with shell execute for which powershell has no built-in support
[Diagnostics.Process]::Start('explorer.exe', '/n, /select, "' + $mp.get_property_string('path') + '"')
}
}
$mp.register_event("client-message", $code)