Vlc.dotnet.form用按钮暂停视频

时间:2020-06-25 13:32:48

标签: c# button vlc.dotnet

我希望有人可以帮助我解决我的问题,我觉得这很容易,但是在解决我要尝试的工作时没有任何运气。我希望能够暂停使用vlc.dotnet播放的视频,以下是我的代码结构的简要摘要。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
using System.IO;
using Vlc.DotNet.Forms;
using System.Threading;
using Vlc.DotNet.Core;
using System.Diagnostics;

namespace TS1_C
{
 public partial class Form1 : Form
    {
 public Form1()
        {
            InitializeComponent();
           
        }

 private void Form1_Load(object sender, EventArgs e)
        {
          button8.Click += new EventHandler(this.button8_Click);
        }

void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
string chosen = listBox1.SelectedItem.ToString();
                    string final = selectedpath2 + "\\" + chosen;  //Path
 playfile(final);
}
 void playfile(string final)
        {
            var control = new VlcControl();
            var currentAssembly = Assembly.GetEntryAssembly();
            var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
            // Default installation path of VideoLAN.LibVLC.Windows
            var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
            control.BeginInit();
            control.VlcLibDirectory = libDirectory;
            control.Dock = DockStyle.Fill;
            control.EndInit();
            panel1.Controls.Add(control);
            control.Play();
        }

 private void button8_Click(object sender, EventArgs e)
        {
           
        }

}
}

如您所见,我有一种方法可以双击列表框中的项,然后使用playfile方法播放它。但是,我希望能够使用称为button8的按钮暂停视频。我什至尝试了很多事情

control.Paused += new System.EventHandler<VlcMediaPlayerPausedEventArgs>(button8_Click);

我将其放入playfile方法,但是似乎没有任何效果。我想知道我使用playfile()播放文件的整个方法吗?是完全错误的。我希望有人可以帮助我实现我所需要的

谢谢

1 个答案:

答案 0 :(得分:0)

您的控件只能初始化一次:

private VlcControl control;

public Form1()
{
            InitializeComponent();
            control = new VlcControl();
            var currentAssembly = Assembly.GetEntryAssembly();
            var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
            // Default installation path of VideoLAN.LibVLC.Windows
            var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
            control.BeginInit();
            control.VlcLibDirectory = libDirectory;
            control.Dock = DockStyle.Fill;
            control.EndInit();
            panel1.Controls.Add(control);
}

然后,您的播放方法可以简化:

 void playfile(string url)
        {
            control.Play(url);
        }

对于您的暂停方法:

 private void button8_Click(object sender, EventArgs e)
        {
           control.Pause();
        }