我有一个WinForms
带有 2 个视频播放器的简单解决方案,一个是Vlc.DotNet,第二个是libvlcsharp
除此之外,我还有一个可以播放两个视频的简单按钮。
因为libvlcsharp
我遵循了这个例子
因为Vlc.DotNet
我用了这个例子
更多我附加了 logFiles Loglibvlcsharp.txt和LogVlcDotNet
这是我的代码
public partial class QueueDisplayVideoView : Form
{
private string[] paths, files;
private int videoIndex = 0;
public LibVLC _libVLC;
public MediaPlayer _mp;
public LibVLCSharp.Shared.Media media;
public QueueDisplayVideoView()
{
InitializeComponent();
Core.Initialize();
_libVLC = new LibVLC(enableDebugLogs:true);
_libVLC.SetLogFile(@"C:\Temp\LogLib.txt");
_mp = new MediaPlayer(_libVLC);
videoView.MediaPlayer = _mp;
}
protected override void OnLoad(EventArgs e)
{
_presenter.OnViewReady();
base.OnLoad(e);
LoadVideoFiles();
SetPlayerAspectRatio();
//StartAutoPlay();
}
private void StartAutoPlay()
{
vlcControl.Play(new Uri(paths[videoIndex]));
_mp.Play(new LibVLCSharp.Shared.Media(_libVLC, new Uri(paths[videoIndex])));
}
private void LoadVideoFiles()
{
var path = some path
paths = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
files = new string[paths.Length];
for (int i = 0; i < paths.Length; i++)
{
files[i] = Path.GetFileName(paths[i]);
}
}
private void SetPlayerAspectRatio()
{
var videoWidth = vlcControl.Width.ToString();
var videoHieght = vlcControl.Height.ToString();
vlcControl.Video.AspectRatio = videoWidth + ":" + videoHieght;
}
private void vlcControl_VlcLibDirectoryNeeded(object sender, Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs e)
{
// var currentAssembly = System.Reflection.Assembly.GetEntryAssembly();
var currentDirectory = @"Q:\bin"; //new FileInfo(currentAssembly.Location).DirectoryName;
// Default installation path of VideoLAN.LibVLC.Windows
var fullPath = Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64");
e.VlcLibDirectory = new DirectoryInfo(fullPath);
}
private void vlcControl_EndReached(object sender, Vlc.DotNet.Core.VlcMediaPlayerEndReachedEventArgs e)
{
GetNextVideoIndex();
ThreadPool.QueueUserWorkItem(_ => vlcControl.Play(new Uri(paths[videoIndex])));
}
private void button1_Click(object sender, EventArgs e)
{
StartAutoPlay();
}
private void GetNextVideoIndex()
{
if (videoIndex < files.Length - 1)
{
videoIndex = videoIndex + 1;
}
else
{
videoIndex = 0;
}
}
}