之前写过一篇文章关于WPF利用VLCPlayer控制Winform窗体句柄封装的视频播放器(链接:https://blog.csdn.net/dnazhd/article/details/102476134),这里换一种方式重写一下视频播放器控件,采用VlcVideoSourceProvider绑定Image控件。
实现步骤:
1、添加对VLC控件的引用
![](https://img-blog.csdnimg.cn/20200121114640416.png)
2、UCVlcPlayer窗体xaml
将方式一中的winform控件:
<WindowsFormsHost Grid.Row="0" Name="playerForm" Background="Transparent">
<WinFormControls:Panel x:Name="panelFormControl"></WinFormControls:Panel>
</WindowsFormsHost>
修改为:
<Image x:Name="VideoImg" Grid.Row="0" Stretch="Fill" VerticalAlignment="Center" HorizontalAlignment="Center"></Image>
3、交互逻辑
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using Vlc.DotNet.Wpf;
namespace VlcPlayerWPFDemo
{
/// <summary>
/// UCVlcPlayer.xaml 的交互逻辑
/// </summary>
public partial class UCVlcPlayer : UserControl
{
private volatile bool m_isDrag;
private string filePath = "";
private double acWidth = 600;
private double acHeight = 440;
private double fullWidth = 600;
private double fullHeight = 440;
private VlcVideoSourceProvider sourceProvider;
publi