0

我希望有人可以帮助我解决我的问题,我觉得这很容易,但是在解决我想做的事情时没有任何运气。我希望能够暂停我正在使用 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() 播放文件的整个方法;是完全错误的。我希望有人可以帮助我努力实现我所需要的

谢谢

4

1 回答 1

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();
        }
于 2020-06-25T18:19:56.610 回答