[英]Playing video yeild black screen with audio(Vlc.DotNet and libvlcsharp)
I have a simple WinForms
solution with 2 video players one is Vlc.DotNet and the second is libvlcsharp我有一个带有 2 个视频播放器的简单WinForms
解决方案,一个是Vlc.DotNet ,第二个是libvlcsharp
and besides that, I have a simple button that plays both videos.除此之外,我有一个简单的按钮可以播放两个视频。
for libvlcsharp
i followed this example对于libvlcsharp
我遵循了这个例子
and for Vlc.DotNet
i used this example对于Vlc.DotNet
我使用了这个例子
further more im attaching both logFiles Loglibvlcsharp.txt and LogVlcDotNet此外,我还附加了日志文件Loglibvlcsharp.txt和LogVlcDotNet
this is my code这是我的代码
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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.