Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

V2023.10.0 #17

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
86b5c1e
Update examples
fsobolev Sep 2, 2023
5cdddfb
Add SDL2 example
fsobolev Sep 2, 2023
bcac35b
Fix OpenGL context creation in SDL
fsobolev Sep 2, 2023
6c341b6
Add SDL example to README
fsobolev Sep 2, 2023
b84fbf8
Add SDL example to docs
fsobolev Sep 2, 2023
d096d51
Simplify SDL example
fsobolev Sep 3, 2023
5eb06bf
Use different videos in examples
fsobolev Sep 3, 2023
13701a8
Use proper values when resizing in GirCore example
fsobolev Sep 3, 2023
ac6bdb9
Add WPF example
fsobolev Sep 20, 2023
10d0207
WPF - Better Project Layout + MPV Control
nlogozzo Sep 21, 2023
0b1b1cb
Create MPVSharp.sln
nlogozzo Sep 21, 2023
5d167b2
WPF - Better Sample
nlogozzo Sep 21, 2023
c197610
WPF - Don't load video on start
fsobolev Sep 21, 2023
9b955f2
WPF - Add Open Video File
nlogozzo Sep 21, 2023
d68d38b
WPF - Various fixes
fsobolev Sep 21, 2023
fa00fc1
Allow setting GetProcAddress function
fsobolev Sep 29, 2023
29c710a
Use Action for opengl callback
fsobolev Sep 29, 2023
a5455ab
GirCore - Use Action for OpenGL callback
fsobolev Sep 29, 2023
6e6bb81
Add Avalonia example
fsobolev Sep 29, 2023
2e0bafa
Allow setting framebuffer
fsobolev Sep 29, 2023
82e0250
Set framebuffer and proc address in Avalonia example
fsobolev Sep 29, 2023
56e7d51
MPVNode - Fix constructor with string, add Empty
fsobolev Oct 2, 2023
b568a84
Add MPVNodeList.Empty
fsobolev Oct 2, 2023
38751c4
Add MPVByteArray.Empty
fsobolev Oct 2, 2023
85d7f41
MPVNode - Add missing comment about exception
fsobolev Oct 2, 2023
9b5dbc9
Add and use Node
fsobolev Oct 2, 2023
346e1b6
Examples - Remove null checks since Node is now used
fsobolev Oct 2, 2023
5705ed3
MPVNode - Ensure correct format when creating with MPVNodeList
fsobolev Oct 2, 2023
5a3398e
Add missing MPVRenderFrameInfo
fsobolev Oct 2, 2023
3cc006c
Improve comments
fsobolev Oct 2, 2023
97ce1bb
Update version and changelog
fsobolev Oct 6, 2023
fea0f4d
Bundled - Update DLL and version
fsobolev Oct 6, 2023
eda21a0
Update README.md
fsobolev Oct 6, 2023
714c296
Fix spelling
fsobolev Oct 6, 2023
cbbd3cd
MPVRenderFrameInfo - Fix TargetTime
fsobolev Oct 6, 2023
118f9e3
Avalonia - Add missing docs + small fixes
fsobolev Oct 6, 2023
d109e76
WPF - Add missing docs
fsobolev Oct 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Docfx/_site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ <h1 id="examples">Examples</h1>
<li><a href="https://github.com/NickvisionApps/MPVSharp/tree/main/Examples/Simple">Simple</a> - basic program playing your file/link. If the file is video, a window will be created by MPV itself.</li>
<li><a href="https://github.com/NickvisionApps/MPVSharp/tree/main/Examples/GirCore">GirCore</a> - GTK4 application playing a video from youtube. Made with <a href="https://github.com/gircore/gir.core">GirCore</a>. Requires GTK4 to be installed.</li>
<li><a href="https://github.com/NickvisionApps/MPVSharp/tree/main/Examples/OpenGL">OpenGL</a> - <a href="https://opentk.net/index.html">OpenTK</a> application playing a video from youtube.</li>
<li><a href="https://github.com/NickvisionApps/MPVSharp/tree/main/Examples/SDL">SDL</a> - Similar to OpenGL example, but uses <a href="https://github.com/flibitijibibo/SDL2-CS/">SDL2-CS</a>. Requires libSDL2 to be installed.</li>
</ul>
<h1 id="chat">Chat</h1>
<p><a href='https://matrix.to/#/#nickvision:matrix.org'><img width='140' alt='Join our room' src='https://user-images.githubusercontent.com/17648453/196094077-c896527d-af6d-4b43-a5d8-e34a00ffd8f6.png'></a></p>
Expand Down
1 change: 1 addition & 0 deletions Docfx/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Refer to MPV documentation to find the list of [options](https://mpv.io/manual/s
* [Simple](https://github.com/NickvisionApps/MPVSharp/tree/main/Examples/Simple) - basic program playing your file/link. If the file is video, a window will be created by MPV itself.
* [GirCore](https://github.com/NickvisionApps/MPVSharp/tree/main/Examples/GirCore) - GTK4 application playing a video from youtube. Made with [GirCore](https://github.com/gircore/gir.core). Requires GTK4 to be installed.
* [OpenGL](https://github.com/NickvisionApps/MPVSharp/tree/main/Examples/OpenGL) - [OpenTK](https://opentk.net/index.html) application playing a video from youtube.
* [SDL](https://github.com/NickvisionApps/MPVSharp/tree/main/Examples/SDL) - Similar to OpenGL example, but uses [SDL2-CS](https://github.com/flibitijibibo/SDL2-CS/). Requires libSDL2 to be installed.

# Chat
<a href='https://matrix.to/#/#nickvision:matrix.org'><img width='140' alt='Join our room' src='https://user-images.githubusercontent.com/17648453/196094077-c896527d-af6d-4b43-a5d8-e34a00ffd8f6.png'/></a>
Expand Down
10 changes: 10 additions & 0 deletions Examples/Avalonia/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaMPV.App"
RequestedThemeVariant="Dark">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
24 changes: 24 additions & 0 deletions Examples/Avalonia/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using AvaloniaMPV.Views;

namespace AvaloniaMPV;

public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}

base.OnFrameworkInitializationCompleted();
}
}
24 changes: 24 additions & 0 deletions Examples/Avalonia/AvaloniaMPV.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.2" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.2" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.2" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.2" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../../Nickvision.MPVSharp/Nickvision.MPVSharp.csproj"/>
</ItemGroup>
</Project>
52 changes: 52 additions & 0 deletions Examples/Avalonia/Controls/MPVControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Avalonia.OpenGL;
using Avalonia.OpenGL.Controls;
using Avalonia.Threading;
using Nickvision.MPVSharp;
using static Avalonia.OpenGL.GlConsts;

namespace AvaloniaMPV.Controls;

public class MPVControl : OpenGlControlBase
fsobolev marked this conversation as resolved.
Show resolved Hide resolved
{
private RenderContext? _ctx;

public readonly Client Player;
fsobolev marked this conversation as resolved.
Show resolved Hide resolved

public MPVControl()
{
Player = new Client();
Player.SetProperty("ytdl", true);
Player.RequestLogMessages("debug");
Player.LogMessageReceived += (sender, e) =>
{
System.Console.Write($"[{e.Prefix}] {e.Text}"); // Log messages (e.Text) end with newline char
};
Player.Initialize();
}

protected override void OnOpenGlInit(GlInterface gl)
{
if (_ctx != null)
{
// OnOpenGlInit is called twice, should be fixed in next Avalonia release
// https://github.com/AvaloniaUI/Avalonia/pull/12713
return;
}
_ctx = Player.CreateRenderContext();
_ctx.GetProcAddressFn = gl.GetProcAddress;
_ctx.SetupGL(() => Dispatcher.UIThread.Post(RequestNextFrameRendering));
}

protected override void OnOpenGlDeinit(GlInterface gl)
{
_ctx?.Dispose();
Player.Dispose();
}

protected override void OnOpenGlRender(GlInterface gl, int fb)
{
gl.ClearColor(0, 0, 0, 1);
gl.Clear(GL_COLOR_BUFFER_BIT);
_ctx?.RenderGL((int)Bounds.Width, (int)Bounds.Height, fb);
}
}
21 changes: 21 additions & 0 deletions Examples/Avalonia/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Avalonia;
using System;

namespace AvaloniaMPV;

class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
10 changes: 10 additions & 0 deletions Examples/Avalonia/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:AvaloniaMPV.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaMPV.Views.MainWindow"
Title="Avalonia MPV# Example">
<views:PlayerView/>
</Window>
11 changes: 11 additions & 0 deletions Examples/Avalonia/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Avalonia.Controls;

namespace AvaloniaMPV.Views;

public partial class MainWindow : Window
{
public MainWindow()
fsobolev marked this conversation as resolved.
Show resolved Hide resolved
{
InitializeComponent();
}
}
13 changes: 13 additions & 0 deletions Examples/Avalonia/Views/PlayerView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:AvaloniaMPV.Controls"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaMPV.Views.PlayerView">
<Grid Background="#2b2b2b" RowDefinitions="* 48" ColumnDefinitions="100 * 100">
<controls:MPVControl x:Name="MPVControl" Grid.Row="0" Grid.ColumnSpan="3" />
<Button x:Name="PauseButton" Margin="6 6" Click="OnPauseClicked" Grid.Row="1" Grid.Column="0">Loading...</Button>
<TextBlock x:Name="TimeLabel" Margin="12 6" VerticalAlignment="Center" TextAlignment="Right" FontWeight="Bold" Grid.Row="1" Grid.Column="2">--:--</TextBlock>
</Grid>
</UserControl>
41 changes: 41 additions & 0 deletions Examples/Avalonia/Views/PlayerView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
using AvaloniaMPV.Controls;
using Nickvision.MPVSharp;

namespace AvaloniaMPV.Views;

public partial class PlayerView : UserControl
fsobolev marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly Client _player;

public PlayerView()
{
InitializeComponent();
_player = MPVControl.Player;
_player.LoadFile("https://www.youtube.com/watch?v=_cMxraX_5RE");
_player.PropertyChanged += (sender, e) => Dispatcher.UIThread.Invoke(() => OnMPVPropertyChanged(sender ,e));
_player.ObserveProperty("pause");
_player.ObserveProperty("time-pos");
}

public void OnMPVPropertyChanged(object? sender, PropertyChangedEventArgs e)
fsobolev marked this conversation as resolved.
Show resolved Hide resolved
{
switch (e.Name)
{
case "pause":
PauseButton.Content = (bool)e.Node ? "Paused" : "Playing";
break;
case "time-pos":
TimeLabel.Text = TimeSpan.FromSeconds((double)e.Node).ToString(@"mm\:ss");
break;
}
}

public void OnPauseClicked(object sender, RoutedEventArgs e)
{
_player.CyclePause();
}
}
18 changes: 18 additions & 0 deletions Examples/Avalonia/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<!-- This manifest is used on Windows only.
Don't remove it as it might cause problems with window transparency and embeded controls.

Check failure on line 4 in Examples/Avalonia/app.manifest

View workflow job for this annotation

GitHub Actions / codespell

embeded ==> embedded
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
<assemblyIdentity version="1.0.0.0" name="AvaloniaMPV.Desktop"/>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->

<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>
2 changes: 0 additions & 2 deletions Examples/GirCore/GirCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 8 additions & 4 deletions Examples/GirCore/MainWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nickvision.MPVSharp;
using System;

namespace Nickvision.MPVSharp.Examples.GirCore;

Expand All @@ -14,6 +15,7 @@ public partial class MainWindow : Gtk.ApplicationWindow
private readonly Gtk.GLArea _glArea;
private readonly Client _player;
private RenderContext? _ctx;
private (int, int) _size;

/// <summary>
/// Construct window
Expand All @@ -31,6 +33,7 @@ public MainWindow(Gtk.Application application)
SetChild(_glArea);
_glArea.SetVexpand(true);
_glArea.SetHexpand(true);
_size = (0, 0);
// Create MPV client
_player = new Client();
_player.SetProperty("ytdl", true);
Expand All @@ -43,11 +46,11 @@ public MainWindow(Gtk.Application application)
{
if (e.Name == "pause")
{
pauseButton.SetIconName((bool)e.Node! ? "media-playback-start-symbolic" : "media-playback-pause-symbolic");
pauseButton.SetIconName((bool)e.Node ? "media-playback-start-symbolic" : "media-playback-pause-symbolic");
}
if (e.Name == "media-title")
{
title.SetLabel((string)e.Node!);
title.SetLabel((string)e.Node);
}
};
_player.ObserveProperty("pause");
Expand All @@ -57,6 +60,7 @@ public MainWindow(Gtk.Application application)
_glArea.OnRealize += OnRealizeGLArea;
_glArea.OnUnrealize += OnUnrealizeGLArea;
_glArea.OnRender += OnRenderGLArea;
_glArea.OnResize += (_, e) => _size = (e.Width, e.Height);
// Keyboard shortcuts
var keyboardController = Gtk.EventControllerKey.New();
keyboardController.SetPropagationPhase(Gtk.PropagationPhase.Capture);
Expand All @@ -77,7 +81,7 @@ private void OnRealizeGLArea(Gtk.Widget sender, EventArgs e)
_ctx = _player.CreateRenderContext();
// We create callback for MPV to call every time the screen needs to be redrawn,
// the callback calls GtkGLArea.QueueDraw which in turn makes RenderContext draw image
_ctx.SetupGL((x) => GLib.Functions.IdleAdd(0, () =>
_ctx.SetupGL(() => GLib.Functions.IdleAdd(0, () =>
{
_glArea.QueueDraw(); // QueueDraw must be called from GTK thread
return false;
Expand All @@ -104,7 +108,7 @@ private void OnUnrealizeGLArea(Gtk.Widget sender, EventArgs e)
/// <param name="e">EventArgs</param>
private bool OnRenderGLArea(Gtk.Widget sender, EventArgs e)
{
_ctx?.RenderGL(_glArea.GetAllocatedWidth(), _glArea.GetAllocatedHeight());
_ctx?.RenderGL(_size.Item1, _size.Item2);
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion Examples/OpenGL/MPVWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework;
using System;

namespace Nickvision.MPVSharp.Examples.OpenGL;

Expand Down Expand Up @@ -42,7 +43,7 @@ protected override void OnLoad()
_ctx = _player.CreateRenderContext();
// GameWindow calls OnRenderFrame, well, every frame, so we don't need callback for MPV to tell us when to draw
_ctx.SetupGL(null);
_player.LoadFile("https://www.youtube.com/watch?v=UXqq0ZvbOnk");
_player.LoadFile("https://www.youtube.com/watch?v=WhWc3b3KhnY");
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion Examples/OpenGL/OpenGL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
Loading