栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在PyGI中获取窗口句柄

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在PyGI中获取窗口句柄

我终于明白了。为了解决“窗口句柄”问题,我使用了Marwin Schmitt的变通方法/
hack(请参阅此处):

def _on_video_realize(self, widget):    # The window handle must be retrieved first in GUI-thread and before    # playing pipeline.    video_window = self._drawing_area.get_property('window')    if sys.platform == "win32":        if not video_window.ensure_native(): print("Error - video playback requires a native window")        ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p        ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object]        drawingarea_gpointer = ctypes.pythonapi.PyCapsule_GetPointer(video_window.__gpointer__, None)        gdkdll = ctypes.CDLL ("libgdk-3-0.dll")        self._video_window_handle = gdkdll.gdk_win32_window_get_handle(drawingarea_gpointer)    else:        self._video_window_handle = video_window.get_xid()

但是还有一个问题,就是从来没有调用过“同步消息”处理程序。我发现并非所有的视频接收器都支持嵌入式视频,请参见此处。例如,

d3dvideosink
确实支持嵌入式视频,但是我在虚拟机上运行Windows,即使激活了3D硬件加速,它也可能无法工作。在非虚拟Windows上运行相同的代码将导致对“
sync-message”处理程序的回调,可以在其中设置先前获取的窗口处理程序:

def _on_player_sync_message(self, bus, message):    if message.get_structure() is None:        return    if not GstVideo.is_video_overlay_prepare_window_handle_message(message):        return    imagesink = message.src    imagesink.set_property("force-aspect-ratio", True)    imagesink.set_window_handle(self._video_window_handle)

Windows上的播放现在可以正常工作。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/646089.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号