由于项目之前使用libVLC制作的播放器没有全屏功能,现在需要添加全屏功能。而实现全屏功能后需要控件捕获鼠标消息。不做处理的话,鼠标消息会被vlc捕获!这里就需要VLC忽略掉鼠标消息!
所以,需在创建完媒体播放器后,调用 libvlc_video_set_key_input() 和 libvlc_video_set_mouse_input() 即可,这样 libVLC 就可以忽略键盘和鼠标事件了:
private libvlc_media_player_t Create_MediaPlayer(libvlc_instance_t libvlc_instance, IntPtr handle)
{
libvlc_media_player_t libvlc_media_player = IntPtr.Zero;
try
{
if (libvlc_instance == IntPtr.Zero ||
libvlc_instance == null ||
handle == IntPtr.Zero ||
handle == null)
{
return IntPtr.Zero;
}
//创建播放器
libvlc_media_player = VlcMethods.libvlc_media_player_new(libvlc_instance);
if (libvlc_media_player == null || libvlc_media_player == IntPtr.Zero)
{
return IntPtr.Zero;
}
// 忽略事件处理
VlcMethods.libvlc_video_set_key_input(libvlc_media_player, 0);
VlcMethods.libvlc_video_set_mouse_input(libvlc_media_player, 0);
//设置播放窗口
VlcMethods.libvlc_media_player_set_hwnd(libvlc_media_player, (int)handle);
return libvlc_media_player;
}
catch
{
VlcMethods.libvlc_media_player_release(libvlc_media_player);
return IntPtr.Zero;
}
}
使用之前导入函数:
//设置捕获键盘消息
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void libvlc_video_set_key_input(libvlc_media_player_t p_mi, uint on);
//设置捕获鼠标消息
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void libvlc_video_set_mouse_input(libvlc_media_player_t p_mi, uint on);