我正在尝试获取SDL窗口的Window ID,以便给VLC,以便它可以在窗口中播放视频。
作为Python的新手,我隐约意识到这与变量类型的转换有关,可以很好地使用SDL,并使用正确的python绑定...
带错误的行是“win_id = SDL_GetWindowID(window)”
这是我的代码;
import sys
import sdl2.ext
import vlc
import ctypes
from sdl2 import *
RESOURCES = sdl2.ext.Resources(__file__, "resources")
sdl2.ext.init()
window = sdl2.ext.Window("Hello World!", size=(640, 480))
window.show()
factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
sprite = factory.from_image(RESOURCES.get_path("hello.bmp"))
spriterenderer = factory.create_sprite_render_system(window)
spriterenderer.render(sprite)
vlcInstance = vlc.Instance("--no-xlib")
player = vlcInstance.media_player_new()
win_id = SDL_GetWindowID(window)
player.set_xwindow(win_id)
player.set_mrl("agro.mp4")
player.play()
processor = sdl2.ext.TestEventProcessor()
processor.run(window)
sdl2.ext.quit()
您使用SDL_GetWindowID获得的是SDL的内部窗口ID,它本身在例如事件。你需要的是X11窗口ID,你可以通过SDL_GetWindowWMInfo获得。然而,这需要SDL版本化的一些技巧,例如(如果SDL版本更改但pysdl2未更新,我不确定在python中调用它是否安全):
wminfo = SDL_SysWMinfo();
SDL_GetVersion(wminfo.version);
if(SDL_GetWindowWMInfo(window.window, wminfo) == 0):
print("can't get SDL WM info");
sys.exit(1);
win_id = wminfo.info.x11.window;
然后使用win_id
提供给vlc。