I am developing a multi-platform application that manipulates VLC through python-vlc and makes it draw in a Tkinter window.
I am using the following simplified code (inspired from the tkvlc.py
example from python-vlc):
import os
import platform
import sys
import tkinter
from ctypes import c_void_p, cdll
from threading import Thread
import vlc
system = platform.system()
if system == "Darwin":
# find the accurate Tk lib for Mac
libtk = "libtk%s.dylib" % (tkinter.TkVersion,)
if "TK_LIBRARY_PATH" in os.environ:
libtk = os.path.join(os.environ["TK_LIBRARY_PATH"], libtk)
else:
prefix = getattr(sys, "base_prefix", sys.prefix)
libtk = os.path.join(prefix, "lib", libtk)
dylib = cdll.LoadLibrary(libtk)
_GetNSView = dylib.TkMacOSXGetRootControl
_GetNSView.restype = c_void_p
_GetNSView.argtypes = (c_void_p,)
del dylib
class Window(tkinter.Tk):
def register(self, player):
id = self.winfo_id()
print(id)
if system == "Darwin":
player.set_nsobject(_GetNSView(id))
elif system == "Linux":
player.set_xwindow(id)
elif system == "Windows":
player.set_hwnd(id)
def play(instance, player, path):
media = instance.media_new_path(path)
player.set_media(media)
player.play()
if __name__ == "__main__":
instance = vlc.Instance()
player = instance.media_player_new()
window = Window()
window.register(player)
thread = Thread(target=play, args=(instance, player, sys.argv[1]))
thread.start()
window.mainloop()
On MacOS, the size of the video is not adapted to the size of the window. If the video is to large for the window, it is cropped, if it is too small, it stands in the left bottom corner and is surrounded by black. The size of the video is updated only when the window is resized. Here is a video capture of the problem. This does not occur on Linux or on Window.
The same problem occurs with the tkvlc.py
example from python-vlc) if the call to the OnResize
method is blocked line 471 (the method resizes the window to have the size ratio of the video).
What should I do to force VLC to resize the video to fit the window automatically, as it does by default on other OSes?