通过c#控制VLC

我正在编写一个应用程序,它将打开vlc,将文件添加到其播放列表中,然后播放它。 我在最后2个问题上遇到了一些问题。

AXVLC.VLCPlugin alxplugin1 = new AXVLC.VLCPlugin(); alxplugin1.addTarget("C:\\test.avi", null, AXVLC.VLCPlaylistMode.VLCPlayListInsert, 0); alxplugin1.play(); 

这不行……有什么想法吗?

谢谢

较新版本的VLC在文件名的开头需要“file:///”。 如果你添加它应该工作。 请尝试以下操作,看看它是否能解决您的问题。 use: alxplugin1.addTarget("file:///" + "C:\\test.avi", null, AXVLC.VLCPlaylistMode.VLCPlayListReplaceAndGo,0);

C#可以通过它的COM层访问VLC。 首先要注册的是axvlc.dll。 打开cmd窗口并键入:

 C:\Windows\System32\regsvr32.exe C:\Program Files (x86)\VideoLAN\VLC\axvlc.dll 

您应该收到一个确认您的dll已成功注册的对话框。 打开VisualStudio并创建一个新的WinForms项目并添加对COM VLC COM对象的引用。 转到Form cs文件

 namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); AXVLC.VLCPlugin2Class p = new AXVLC.VLCPlugin2Class(); p.addTarget("C:\\zk.m4a", null, VLCPlaylistMode.VLCPlayListInsert, 0); p.play(); } } } 

注意:不推荐使用VLCPluginClass,使用VLCPlugin2Class