argh
This commit is contained in:
39
src/Scripts/C-Sharp/dynamic-context-menu-items.cs
Normal file
39
src/Scripts/C-Sharp/dynamic-context-menu-items.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/Scripts/C-Sharp/key-binding.cs
Normal file
29
src/Scripts/C-Sharp/key-binding.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/Scripts/C-Sharp/observe-property-and-draw-text.cs
Normal file
21
src/Scripts/C-Sharp/observe-property-and-draw-text.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
45
src/Scripts/C-Sharp/pause-when-minimize.cs
Normal file
45
src/Scripts/C-Sharp/pause-when-minimize.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user