A .NET media player UI to use with any media player, for WPF and Avalonia
Currently supports MPV and NAudio for WPF, and BASS for Avalonia
- Full customizable UI with seek bar and volume control
- Fullscreen support with UI displaying on hover (WPF)
- Supports mouse and keyboard shortcuts
- Can be customized to work with any media player
- Designed with MVVM and databinding in mind
Todo
Overview
Using MPV Player in WPF
Using NAudio Player in WPF
Using BASS Player in Avalonia
Using Custom Players
Licensing
- Integrate MPV video player in Avalonia (OpenGL integration, full-screen UI support)
- Contributions are welcomed to add new styles and color themes for both WPF and Avalonia!
The basic syntax is to create a MediaPlayer
with an implementation deriving from PlayerHostBase
inside.
<media:MediaPlayer x:Name="Player">
<media:NAudioPlayerHost Source="MyAudio.mp3" />
</media:MediaPlayer>
View all properties in the Wiki
Gets or sets whether to change volume with the mouse wheel.
Gets or sets whether the Play/Pause button is visible.
Gets or sets whether the Stop button is visible.
Gets or sets whether the Loop button is visible.
Gets or sets whether the volume is visible.
Gets or sets whether the Speed button is visible.
Gets or sets whether the seek bar is visible.
Gets or sets the mouse action that will trigger full-screen mode.
Gets or sets the mouse action that will trigger pause.
Gets or sets how time is displayed within the player.
Gets or sets the interval in milliseconds between consecutive seeks. Default = 500.
View all properties in the Wiki
Gets or sets whether to auto-play the file when setting the source.
Gets or sets whether the media file is playing or paused.
Gets or sets whether to show the video.
Gets or sets whether to loop.
Gets or sets the playback position.
Gets or sets the path to the media file to play. If resetting the same file path, you may need to first set an empty string before resetting the value to ensure it detects the value change.
Gets or sets the speed multiplier.
Gets or sets the speed as an integer, where normal playback is 0. Useful for binding to a slider.
Gets or sets the display title of the media file. A title is set by default and you can override it using this property.
Gets or sets the volume.
-
Add MediaPlayer.Wpf.Mpv to your project.
-
Drop this code into your page.
xmlns:media="https://github.com/mysteryx93/MediaPlayerUI.NET"
...
<media:MediaPlayer x:Name="Player">
<media:MpvPlayerHost Source="MyVideo.mp4" />
</media:MediaPlayer>
- Download the latest version of libmpv from here. MPV will require a different DLL for x64 and x86.
Copy the DLL into the project folder and add this to your project file
<ItemGroup>
<None Update="mpv-1.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Optionally, set DllPath on MpvPlayerHost to help find the DLL.
- To add keyboard shortcuts, add this code to your window
<Window.InputBindings>
<KeyBinding Key="Space" Command="{Binding PlayPauseCommand, ElementName=Player}" />
<KeyBinding Key="Right" Command="{Binding SeekCommand, ElementName=Player}" CommandParameter="{media:Int32 1}" />
<KeyBinding Key="Right" Modifiers="Ctrl" Command="{Binding SeekCommand, ElementName=Player}" CommandParameter="{media:Int32 10}" />
<KeyBinding Key="Left" Command="{Binding SeekCommand, ElementName=Player}" CommandParameter="{media:Int32 -1}" />
<KeyBinding Key="Left" Modifiers="Ctrl" Command="{Binding SeekCommand, ElementName=Player}" CommandParameter="{media:Int32 -10}" />
<KeyBinding Key="Up" Command="{Binding ChangeVolumeCommand, ElementName=Player}" CommandParameter="{media:Int32 5}" />
<KeyBinding Key="Down" Command="{Binding ChangeVolumeCommand, ElementName=Player}" CommandParameter="{media:Int32 -5}" />
<KeyBinding Key="Enter" Modifiers="Alt" Command="{Binding ToggleFullScreenCommand, ElementName=Player}" />
</Window.InputBindings>
Audio-only.
-
Add MediaPlayer.Wpf.NAudio to your project.
-
Drop this code into your page.
xmlns:media="https://github.com/mysteryx93/MediaPlayerUI.NET"
...
<media:MediaPlayer x:Name="Player">
<media:NAudioPlayerHost Source="MyAudio.mp3" />
</media:MediaPlayer>
Standard PlayerHostBase properties
Gets or sets the playback rate as a double, where 1.0 is normal speed, 0.5 is half-speed, and 2 is double-speed. Default = 1.
Gets or sets the playback pitch as a double, rising or lowering the pitch by given factor without altering speed. Default = 1.
Gets or sets the interval in milliseconds at which the position bar is updated.
Gets or sets whether to enable pitch-shifting effects. By default, effects are enabled if Rate, Pitch or Speed are set before loading a media file. If file is loaded at normal speed and you want to allow changing it later, this property forces initializing the effects module. This property must be set before playback. Default = False.
Gets or sets a value that will be multiplied to the volume. Default = 1.
Occurs when the player throws an error.
Occurs when media playback is finished.
Audio-only. Supports altering Pitch, Rate and Speed. Set UseEffects="True" or set Pitch/Rate/Speed at design-time.
BASS is free for non-commercial use. If you are a non-commercial entity (eg. an individual) and you are not making any money from your product (through sales, advertising, etc) then you can use BASS in it for free. Otherwise, a license will be required.
Pitch-shifting audio quality is better with BASS than with NAudio/SpeedTouch.
-
Add MediaPlayer.Avalonia.Bass to your project.
-
Add styles to App.axaml
<Application.Styles>
<FluentTheme Mode="Light"/>
<StyleInclude Source="avares://MediaPlayer.Avalonia/Styles/Default/Theme.axaml" />
<StyleInclude Source="avares://MediaPlayer.Avalonia/Styles/Colors/Gray.axaml" />
</Application.Styles>
- Drop this code into your page.
xmlns:media="https://github.com/mysteryx93/MediaPlayerUI.NET"
...
<media:MediaPlayer x:Name="Player">
<media:BassPlayerHost Source="MyAudio.mp3" />
</media:MediaPlayer>
bass.dll
and bass_fx.dll
will be required, and you can add other plugins to support more input formats. This library will auto-load all plugins in the folder.
Simply reference that project and you'll get all the DLLs for each platform.
Gets or sets whether to use the quick mode that substantially speeds up the algorithm but may degrade the sound quality by a small amount. Default = False.
Gets or sets whether to enable the Anti-Alias filter. Default = False.
Gets or sets the Anti-Alias filter length. Default = 32.
Gets or sets the sample rate conversion quality... 0 = linear interpolation, 1 = 8 point sinc interpolation, 2 = 16 point sinc interpolation, 3 = 32 point sinc interpolation, 4 = 64 point sinc interpolation. Default = 4, set lower for better performance.
Gets or sets whether to process effects in 32-bit. True for 32-bit, False for 16-bit. Default = False, set to True for best quality.
Gets or sets whether to round the pitch to the nearest fraction when pitch-shifting for improved quality.
Gets the pitch rounding error when EffectsRoundPitch is true.
Gets or sets whether to skip tempo adjustment for maximum audio quality.
Gets or sets the playback pitch as a double, rising or lowering the pitch by given factor without altering speed. Default = 1.
Gets or sets the interval in milliseconds at which the position bar is updated.
Gets or sets the playback rate as a double, where 1.0 is normal speed, 0.5 is half-speed, and 2 is double-speed. Default = 1.
Gets or sets whether to enable pitch-shifting effects. By default, effects are enabled if Rate, Pitch or Speed are set before loading a media file. If file is loaded at normal speed and you want to allow changing it later, this property forces initializing the effects module. This property must be set before playback. Default = False.
Gets or sets a value that will be multiplied to the volume. Default = 1.
Gets or sets the device output sample rate. 0 = auto-detected. On Linux, it cannot be auto-detected and must be set manually if different than 48000.
Occurs when the player throws an error.
Occurs when media playback is finished.
You can get information about auto-loaded BASS plugins and supported formats using the BassDevice class.
Look at MediaPlayer.Wpf.Mpv or MediaPlayer.Avalonia.Bass. Integrating a new player is quite straightforward.
VapourSynthViewer.NET is an example of using the UI for previewing Vapoursynth video scripts.
This library is licensed under MIT.
MPV.NET-lib is 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.
NAudio is licensed under MIT. SoundTouch is licensed under LGPL v2.1
BASS is free for non-commercial use. If you are a non-commercial entity (eg. an individual) and you are not making any money from your product (through sales, advertising, etc) then you can use BASS in it for free. Otherwise, one of the following licences will be required.
ManagedBass is licensed under MIT.
Brought to you by Etienne Charland aka Hanuman. Made by a Lightworker in his spare time.