https://blog.csdn.net/confused_kitten/article/details/134332261
1.Nuget添加类库Dove.Avalonia.Extensions.Media,项目路径https://github.com/michael-eddy/Avalonia.Extensions/
2.Nuget添加VideoLAN.LibVLC.Windows
Platform LibVLC Package Minimum OS Version
Windows VideoLAN.LibVLC.Windows Windows XP
UWP VideoLAN.LibVLC.UWP Windows 10
Mac VideoLAN.LibVLC.Mac macOS 10.7
Android VideoLAN.LibVLC.Android Android 2.3
iOS VideoLAN.LibVLC.iOS iOS 8.4
tvOS VideoLAN.LibVLC.tvOS tvOS 10.2
Linux Linux N/A
2.由于Dove.Avalonia.Extensions.Media 2.0.2的依赖需要Avalonia版本≥11.0.5,我将的demo项目更新至Avalonia11.0.5
3.在Program.cs 文件的BuildAvaloniaApp中添加UseVideoView()
using Avalonia;
using Avalonia.Extensions.Media;
using System;
namespace AvaloniaDemo
{
internal 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()
.UseVideoView()
.LogToTrace();
}
}
4.使用控件
<PlayerView x:Name="playerView"/>
5.播放视频
VideoView = this.FindControl<PlayerView>("playerView");
string baseurl = Directory.GetCurrentDirectory();
var path = System.IO.Path.Combine(baseurl, @"Assets\hahahge.mp4");
VideoView.Play(path);
5. demo下载地址:https://gitee.com/confusedkitten/avalonia-demo
————————————————
版权声明:本文为CSDN博主「confused_kitten」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/confused_kitten/article/details/134332261