c# - GTK 中的 LibVLC.NET#

标签 c# vlc gtk# libvlc

我使用 LibVLC.NET GTK# 中的包装器。我已经使用这个例子播放了视频:

LibVLCLibrary library = LibVLCLibrary.Load(null);
IntPtr inst, mp, m;

inst = library.libvlc_new();                                      // Load the VLC engine 
m = library.libvlc_media_new_location(inst, "path/to/your/file"); // Create a new item 
mp = library.libvlc_media_player_new_from_media(m);               // Create a media player playing environement 
library.libvlc_media_release(m);                                  // No need to keep the media now 
library.libvlc_media_player_play(mp);                             // play the media_player 
Thread.Sleep(10000);                                              // Let it play a bit 
library.libvlc_media_player_stop(mp);                             // Stop playing 
library.libvlc_media_player_release(mp);                          // Free the media_player 
library.libvlc_release(inst);

LibVLCLibrary.Free(library);

但是视频在另一个新窗口中播放,现在我需要在 GTK# 中设置窗口或(更好的)容器来播放视频。我应该怎么做?

更新: 我在 LibVLC.NET 中找到了这个函数:

 //==========================================================================
// void libvlc_video_set_format_callbacks (libvlc_media_player_t *mp, libvlc_video_format_cb setup, libvlc_video_cleanup_cb cleanup)

//==========================================================================
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate uint libvlc_video_format_cb(ref IntPtr opaque, ref uint chroma, ref uint width, ref uint height, ref uint pitches, ref uint lines);

//==========================================================================
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void libvlc_video_cleanup_cb(IntPtr opaque);

//==========================================================================
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void libvlc_video_set_format_callbacks_signature(IntPtr mp, libvlc_video_format_cb setup, libvlc_video_cleanup_cb cleanup);

//==========================================================================
private readonly libvlc_video_set_format_callbacks_signature m_libvlc_video_set_format_callbacks;

//==========================================================================
public void libvlc_video_set_format_callbacks(IntPtr mp, libvlc_video_format_cb setup, libvlc_video_cleanup_cb cleanup)
{
  VerifyAccess();

  m_libvlc_video_set_format_callbacks(mp, setup, cleanup);
}

/*
  void libvlc_media_player_set_nsobject (libvlc_media_player_t *p_mi, void *drawable)
  void * libvlc_media_player_get_nsobject (libvlc_media_player_t *p_mi)
  void libvlc_media_player_set_agl (libvlc_media_player_t *p_mi, uint32_t drawable)
  uint32_t libvlc_media_player_get_agl (libvlc_media_player_t *p_mi)
  void libvlc_media_player_set_xwindow (libvlc_media_player_t *p_mi, uint32_t drawable)
  uint32_t libvlc_media_player_get_xwindow (libvlc_media_player_t *p_mi)
  void libvlc_media_player_set_hwnd (libvlc_media_player_t *p_mi, void *drawable)
  void * libvlc_media_player_get_hwnd (libvlc_media_player_t *p_mi)
*/

在评论中提到了 libvlc_media_player_set_hwnd (),这个函数可能会以某种方式取代它或提供与 libvlc_media_player_set_hwnd () 相同的机会?

最佳答案

根据平台的不同,您需要调用 libvlc_media_player_set_xwindow (Linux)、libvlc_media_player_set_hwnd (Windows) 或 libvlc_media_player_set_nsobject (OSX)。

第二个参数是一个整数,它是您要嵌入视频的原生组件的句柄。

像 GTK/GTK# 这样的工具包应该在组件上提供一个方法,使您能够获取此窗口处理程序。

例如,此 C# 代码可用于从 GTK 小部件获取所需的窗口句柄

private static Int32 Wid(Widget widget) {
    IntPtr windowPtr = gtk_widget_get_window(widget.Handle);
    if(windowPtr != IntPtr.Zero) {
        IntPtr xidPtr = gdk_x11_drawable_get_xid(windowPtr);
        if(xidPtr != IntPtr.Zero) {
            return xidPtr.ToInt32();
        }
    }
    return 0;
}

您只需在创建媒体播放器和 native 组件后执行此操作一次,无需在每次播放媒​​体时都执行此操作。

关于c# - GTK 中的 LibVLC.NET#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23072724/

相关文章:

c# - 在列表框中扩展所选项目的高度

python - 用 VLC 播放视频文件,然后退出 VLC

ffmpeg - 将流式 MPEG-4 原始数据转换为 H.264

c# - 来自 C# 中另一个线程的事件

c# - 存储在数据库中时图像的大小

c# - 调试错过的广播数据报,它出现在 wireshark 中,但不出现在 C# 应用程序中?

c# - 与GTKSharp应用程序一起不断调用方法

c# - Gtk# 有键值枚举吗?

c# 表达式 lambda 到 vb.net

c++ - 在一个进程中使用和不使用代理运行 VLC