我正在使用libvlc开发的播放器,c#。有全屏按钮。我试图将mousedoubleclick事件添加到面板(播放视频),它在我们不播放视频时工作;但是当视频开始播放时它不起作用。因此我将相同的事件添加到播放器中但仍然无效。
事件的定义:
this.player.MouseDoubleClick += new MouseEventHandler(panel1_MouseDoubleClick);
定义:
private vlc.DotNet.Forms.VlcControl player;
有没有其他方法可以将鼠标双击事件添加到vlc播放器中?
答案 0 :(得分:9)
Panel1:“panelVideo”拥有“Vlc.DotNet.Forms.VlcControl”
在运行时创建的Panel2:“panelDoubleClick”和“vlcControl.Controls.Add(panelDoubleClick);”
Panel2:设置panelDoubleClick.BackColor = Color.Transparent ;
Panel2:添加双击事件hantler以切换全屏panelDoubleClick.MouseDoubleClick + = new MouseEventHandler(panelDoubleClick_MouseDoubleClick);
Vlc.DotNet.Forms.VlcControl vlcControl;
Vlc.DotNet.Core.Medias.PathMedia Media2Play;
public void PlayMedia(string fileName)
{
if (Vlc.DotNet.Core.VlcContext.IsInitialized == false)
initVLC();
//StopVLC();
//Panel1: "panelVideo" holds "Vlc.DotNet.Forms.VlcControl"
//Panel2: "panelDoubleClick" created at runtime and "vlcControl.Controls.Add(panelDoubleClick);"
//Panel2: panelDoubleClick.BackColor = Color.Transparent;
//panelDoubleClick.MouseDoubleClick += panelDoubleClick_MouseDoubleClick;
vlcControl = new Vlc.DotNet.Forms.VlcControl();
vlcControl.CreateControl();
vlcControl.Dock = DockStyle.Fill;
this.panelVideo.Controls.Add(vlcControl);//panelVideo is manin container panel.
//initEvents();//VLC player events
Panel panelDoubleClick = new Panel();// this panel requires to catche double click evetns.
panelDoubleClick.Dock = DockStyle.Fill;
panelDoubleClick.BackColor = Color.Transparent;
panelDoubleClick.MouseDoubleClick += new MouseEventHandler(panelDoubleClick_MouseDoubleClick); ;
if (vlcControl != null)
{
Media2Play = new Vlc.DotNet.Core.Medias.PathMedia(fileName);
vlcControl.Media = Media2Play;
vlcControl.Show();
vlcControl.Play();
vlcControl.Controls.Add(panelDoubleClick);
panelDoubleClick.BringToFront();
}
}
private void panelDoubleClick_MouseDoubleClick(object sender, MouseEventArgs e)
{
MessageBox.Show ("ToggleFullScreen();");
}
private void initVLC()
{
try
{
// Set libvlc.dll and libvlccore.dll directory path
string vlcPath = "";
vlcPath = "E:\\VLC\\VLC_minimal";
if (System.IO.Directory.Exists(vlcPath) == false)
{
vlcPath = Application.StartupPath.Trim('\\') + "\\VLC\\";
if (System.IO.Directory.Exists(vlcPath) == false)
{
if (Environment.Is64BitOperatingSystem)
{
vlcPath = "C:\\Program Files (x86)\\VideoLAN\\VLC";
}
else
{
vlcPath = "C:\\Program Files\\VideoLAN\\VLC";
}
if (System.IO.Directory.Exists(vlcPath) == false)
{
MessageBox.Show("VLC cannot be fount on your system.");
Application.Exit();
return;
}
}
}
Vlc.DotNet.Core.VlcContext.LibVlcDllsPath = vlcPath;
// CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64;
// Set the vlc plugins directory path
Vlc.DotNet.Core.VlcContext.LibVlcPluginsPath = Vlc.DotNet.Core.VlcContext.LibVlcDllsPath + "\\pugins";
//CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_AMD64;
// Ignore the VLC configuration file
Vlc.DotNet.Core.VlcContext.StartupOptions.IgnoreConfig = true;
// Enable file based logging
Vlc.DotNet.Core.VlcContext.StartupOptions.LogOptions.LogInFile = false;
// Shows the VLC log console (in addition to the applications window)
Vlc.DotNet.Core.VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;
// Set the log level for the VLC instance
Vlc.DotNet.Core.VlcContext.StartupOptions.LogOptions.Verbosity = Vlc.DotNet.Core.VlcLogVerbosities.None;
Vlc.DotNet.Core.VlcContext.StartupOptions.ScreenSaverEnabled = false;
Vlc.DotNet.Core.VlcContext.StartupOptions.AddOption("--no-video-title");
//hide played media filename on startingto play media.
// Initialize the VlcContext
Vlc.DotNet.Core.VlcContext.Initialize();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}