Vlc.dotnet.form 使用按钮暂停视频
Vlc.dotnet.form pause video with a button
我希望有人可以帮助我解决我的问题,我觉得这似乎很容易,但是没有任何运气来解决我想做的事情。我希望能够使用 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)
{
}
}
}
如您所见,我有一种方法可以双击列表框中的项目并使用播放文件方法播放它。但是,我希望能够使用名为 button8 的按钮暂停视频。我什至尝试了很多东西
control.Paused += new System.EventHandler<VlcMediaPlayerPausedEventArgs>(button8_Click);
我将其放入播放文件方法中,但似乎没有任何效果。我想知道我播放文件的整个方法是否使用 playfile();是完全错误的。我希望有人能帮助我实现我所需要的
谢谢
您的控件应该只初始化一次:
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();
}
我希望有人可以帮助我解决我的问题,我觉得这似乎很容易,但是没有任何运气来解决我想做的事情。我希望能够使用 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)
{
}
}
}
如您所见,我有一种方法可以双击列表框中的项目并使用播放文件方法播放它。但是,我希望能够使用名为 button8 的按钮暂停视频。我什至尝试了很多东西
control.Paused += new System.EventHandler<VlcMediaPlayerPausedEventArgs>(button8_Click);
我将其放入播放文件方法中,但似乎没有任何效果。我想知道我播放文件的整个方法是否使用 playfile();是完全错误的。我希望有人能帮助我实现我所需要的
谢谢
您的控件应该只初始化一次:
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();
}