[英]LibVLC.NET in GTK#
I use LibVLC.NET wrapper in GTK#. 我在GTK#中使用LibVLC.NET包装器。 And I have already played video using this example: 我已经使用以下示例播放了视频:
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);
But video playing in another new window, now i need to set window or (better) container in GTK# which will play video. 但是视频正在另一个新窗口中播放,现在我需要在GTK#中设置窗口或(更好的)容器来播放视频。 How should I do this? 我应该怎么做?
Update: I found this function in LibVLC.NET: 更新:我在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)
*/
In the comments there is mention of libvlc_media_player_set_hwnd (), may be this function somehow replace it or give access to the same opportunities as libvlc_media_player_set_hwnd ()? 在评论中提到libvlc_media_player_set_hwnd(),可能是此函数以某种方式替换了它,还是提供了与libvlc_media_player_set_hwnd()相同的机会?
Depending on the platform, you need to call libvlc_media_player_set_xwindow (Linux), libvlc_media_player_set_hwnd (Windows), or libvlc_media_player_set_nsobject (OSX). 根据平台的不同,您需要调用libvlc_media_player_set_xwindow(Linux),libvlc_media_player_set_hwnd(Windows)或libvlc_media_player_set_nsobject(OSX)。
The second parameter is an integer that is the handle to the native component that you want to embed the video. 第二个参数是一个整数,它是您要嵌入视频的本机组件的句柄。
Toolkits like GTK/GTK# should provide a method on the component that enables you to get this window handler. GTK / GTK#之类的工具包应在组件上提供一种方法,使您能够获取此窗口处理程序。
For example this C# code can be used to get the needed window handle from a GTK Widget 例如,此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;
}
You only need to do this once after you create your media player and the native component, you do not need to do it each time you play media. 创建媒体播放器和本机组件后,只需执行一次此操作,而不必每次播放媒体时都执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.