簡體   English   中英

播放帶有音頻的視頻產生黑屏(Vlc.DotNet 和 libvlcsharp)

[英]Playing video yeild black screen with audio(Vlc.DotNet and libvlcsharp)

我有一個帶有 2 個視頻播放器的簡單WinForms解決方案,一個是Vlc.DotNet ,第二個是libvlcsharp

除此之外,我有一個簡單的按鈕可以播放兩個視頻。

對於libvlcsharp我遵循了這個例子

對於Vlc.DotNet我使用了這個例子

此外,我還附加了日志文件Loglibvlcsharp.txtLogVlcDotNet

這是我的代碼

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;
        }
    }
}

你試過用這個嗎?
它應該是winforms的原生
您只需在工具箱-> 選擇項目-> com 組件-> windows 媒體播放器中選擇正確的.dll。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM