赞
踩
今天开始继续Avalonia练习。
本节:LibVLC
1.引入
- Dove.Avalonia.Extensions.Media;
- VideoLAN.LibVLC.Windows
2.项目引入
前台代码
- <Window xmlns="https://github.com/avaloniaui"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:vm="using:PlayerAvalonia.ViewModels"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
-
-
- x:Class="PlayerAvalonia.Views.MainWindow"
- x:DataType="vm:MainWindowViewModel"
- Icon="/Assets/avalonia-logo.ico"
- Title="PlayerAvalonia">
-
- <Design.DataContext>
- <!-- This only sets the DataContext for the previewer in an IDE,
- to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
- <vm:MainWindowViewModel/>
- </Design.DataContext>
- <Grid RowDefinitions="30,*">
- <Button Content="测试" Click="Button_Click" Grid.Row="0"/>
- <PlayerView x:Name="playerView" Grid.Row="1"/>
-
- </Grid>
-
-
- </Window>

后台代码
- using Avalonia.Controls;
- using Avalonia.Extensions.Media;
- using Avalonia.Platform.Storage;
- using LibVLCSharp.Shared;
- using System.IO;
-
- namespace PlayerAvalonia.Views
- {
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
-
- }
-
- private void Button_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
- {
- var topLevel = TopLevel.GetTopLevel(this);
-
- // 启动异步操作以打开对话框。
- var files = topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
- {
- Title = "Open Text File",
- AllowMultiple = false
- }).Result;
- //var files = await storage.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
- //{
- // Title = title,
- // //您可以添加自定义文件类型,也可以从内置文件类型添加。请参阅“定义自定义文件类型”,了解如何创建自定义文件类型。
- // FileTypeFilter = new[] { ImageAll, FilePickerFileTypes.TextPlain }
- //});
- if (files.Count > 0)
- {
- PlayerView VideoView = this.FindControl<PlayerView>("playerView");
-
- VideoView.Play(files[0].Path);
-
- }
- }
- }
- }

运行效果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。