C# Vlc.DotNet调用集锦

  • 抓图(未测试:提问:捕获帧并在图片框中显示)
    public Form1()
    {
        InitializeComponent();          

    }
    private void button1_Click(object sender, EventArgs e)
    {
        //Stream uri = new Stream("rtsp://admin:[email protected]:554/");

        // vlcControl1.Play("rtsp://admin:[email protected]:554/");
        // Stream stream = new Stream();

        string uri = "rtsp://admin:[email protected]:554/";
        string[] options = { ":network-caching=500" };


        vlcControl1.Play(new Uri(uri));


        string imgfile = vlcControl1.GetCurrentMedia().Title;
        Size size = vlcControl1.ClientSize;
        //vlcControl1.TakeSnapshot(imgfile, (uint)size.Width, (uint)size.Height);

        Bitmap bmp = new Bitmap(size.Width, size.Height);
        Rectangle rectangle1 = new Rectangle(vlcControl1.Bounds.X, vlcControl1.Bounds.Y, vlcControl1.Bounds.Width, vlcControl1.Bounds.Height);
        pictureBox1.DrawToBitmap(bmp, rectangle1);

    }                             

    void _SnapshotTaken(object sender, VlcMediaPlayerSnapshotTakenEventArgs e)
    {
        e.ToString();
    }
  • 使用VideoLAN.LibVLC.Windows的库

详见另一篇博客:Vlc.DotNet.Forms使用VideoLAN.LibVLC.Windows的库 同步至社区

  • 另VCL控件响应键盘鼠标事件
obj.Video.IsKeyInputEnabled = false;
obj.Video.IsMouseInputEnabled = false;
  • 解决再次播放视频静音失败

        obj.Play(new Uri(urlSub[i]));
        obj.Audio.IsMute = true;

如此确实可以静音,但当再次Play时,静音就失败了。解决办法是使用“VideoOutChanged”事件

//播放状态改变,监听开始视频播放瞬间
obj.VideoOutChanged += Obj_VideoOutChanged;


private void Obj_VideoOutChanged(object sender, Vlc.DotNet.Core.VlcMediaPlayerVideoOutChangedEventArgs e)
{
    VlcControl obj = (VlcControl)sender;
    Control control = obj.Parent;
    if (control != frmOutPut)
    {
        obj.Audio.IsMute = true;
    }
}
  • 视频是否在播放

obj.isPlaying

  • 待续

你可能感兴趣的:(C#,程序开发,笔记,c#,开发语言,ui)