同步操作将从 GiantappMan/Mpv.NET.lib 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
.NET embeddable video/media player based on mpv for WinForms and WPF
If you encounter any bugs or would like to see a feature added then please open an issue. Contributions are very welcome!
This package is available via NuGet.
To use the API wrapper (and player) you will need libmpv.
If you wish to compile libmpv yourself, there is a guide available in the mpv repository.
To enable youtube-dl functionality in the player you will need the youtube-dl executable and the ytdl hook script from mpv which allows mpv to communicate with youtube-dl.
path = "lib\\youtube-dl.exe",
EnableYouTubeDl
method on an instance of MpvPlayer
.
EnableYouTubeDl
.If youtube-dl stops working after working fine, first try updating the executable with the latest version.
If you have any doubts or questions regarding this process, please feel free to open an issue.
This player was designed to work on Windows and tested in WPF and WinForms. Not tested on other platforms.
To overlay controls over the top of the player please start with this Stack Overflow post.
If you're looking for a media player UI, I'd recommend MediaPlayerUI.NET. :)
MpvPlayer
provides 4 constructors:
MpvPlayer()
MpvPlayer(string libMpvPath)
MpvPlayer(IntPtr hwnd)
MpvPlayer(IntPtr hwnd, string libMpvPath)
Constructors #1 and #2 let mpv create it's own window and will not embed it.
Constructors #3 and #4 allow you to specify a hwnd
parameter which should be the handle to the host control where you want to embed the player.
For the constructors where libMpvPath
is not included, the player attempts to load libmpv from: (in order)
Since WPF doesn't keep traditional handles to controls we will need to use a System.Windows.Forms.Control
object (E.g. Panel
or nearly any other WinForms control) to host the mpv instance.
First you will need to add a reference to System.Windows.Forms
in your project:
System.Windows.Forms
, make sure it's ticked and click "OK".Next, you will need to reference the System.Windows.Forms
namespace in XAML:
<Window ...
xmlns:windowsForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
...>
Then create a WindowsFormsHost
with a Panel
from WinForms:
<WindowsFormsHost>
<windowsForms:Panel x:Name="PlayerHost" />
</WindowsFormsHost>
If WindowsFormHost
isn't found you will need to add a reference to WindowsFormsIntegration
to your project:
WindowsFormsIntegration
, making sure it's ticked and clicking "OK".In your .xaml.cs
file create a field/property of type MpvPlayer
and initialise it using one of the constructors outlined above.
In this example we called our Panel
object PlayerHost
so for the hwnd
parameter in the constructor you would pass in PlayerHost.Handle
like so:
player = new MpvPlayer(PlayerHost.Handle);
See Mpv.NET.WPFExample project for a basic example.
You can use any WinForms control, just pass the Handle
property to the MpvPlayer
constructor and you're done! Easy.
See Mpv.NET.WinFormsExample project for a basic example.
You have the option to set the desired quality of the media you're trying to play using youtube-dl.
This can be changed by setting the YouTubeDlVideoQuality
property on an instance of MpvPlayer
.
Note: this will take effect on the next call of Load
.
This "API" is a wrapper around the mpv C API defined in client.h and is utilised by the player.
Simplest way to create an instance of the mpv .NET API and load libmpv:
// Relative path to the DLL.
var dllPath = @"lib\mpv-1.dll";
using (var mpv = new Mpv(dllPath))
{
// code
}
This will provide a friendly interface to the mpv C API and start an event loop which will raise events accordingly.
If you are looking for a more direct approach to the C API you can create an instance of MpvFunctions which allows you to execute the loaded delegates directly:
var dllPath = @"lib\mpv-1.dll";
using (var mpvFunctions = new MpvFunctions(dllPath))
{
// code
}
Be aware, this method does not raise events and an event loop would have to be manually implemented.
If you are looking that start an event loop you will need to create an instance of MpvFunctions, create and initialise mpv, create an instance of MpvEventLoop and start it:
var dllPath = @"lib\mpv-1.dll";
// Create an instance of MpvFunctions.
var functions = new MpvFunctions(dllPath);
// Create mpv
var handle = functions.Create();
// Initialise mpv
functions.Initialise(handle);
// Create an instance of MpvEventLoop, passing in a callback argument
// which will be invoked when an event comes in.
using (var eventLoop = new MpvEventLoop(callback, handle, functions))
{
// Start the event loop.
eventLoop.Start();
}
The code above does not contain any error checking, most of the mpv functions return an MpvError which indicates whether an error has occured.
The libmpv C API specifically is licensed under ICS, this means that a wrapper such as this can be licensed under MIT.
The rest of libmpv is licensed under GPLv2 by default, which means that any work utilising this wrapper in conjunction with libmpv is subject to GPLv2, unless libmpv is compiled using LGPL.
In simple terms, once you use the "libmpv" files (DLL) you downloaded, your application must be licensed under GPLv2.
See here for more information.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。