I'm using libVLC to play a video, and trying to detect when the video window is clicked. It works fine on a Windows XP machine, but not on a machine with an identical Python setup running Windows 7...
Both are running Python 2.7 and wxPython 2.8.
I tried with wxPython 4.0.3 (latest version on pip), but same behavior.
I posted a very stripped down version with a test video and the vlc.py binding here:
Note that libVLC has a parameter called "video_set_mouse_input(0)" that when enabled shows a debug message when the VLC window is clicked, and doesn't show the message when disabled. So it works, but isn't passing the clicks to the main window on Windows 7. On the XP box the main window receives the clicks regardless of video_set_mouse_input().
#! /usr/bin/python
import os, sys, time
import vlc
import wx
print "wxPython version %s" % wx.version()
current_directory = os.path.dirname(os.path.realpath(__file__))
class Player(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "VLC Test",
pos=wx.DefaultPosition, size=(850, 560))
self.program_launch_time = time.time()
self.video_initted = False
self.Bind(wx.EVT_CLOSE, self.onExit)
self.videopanel = wx.Panel(self, -1, style= wx.WANTS_CHARS)
# working only with VLC lib v3+ on XP... Not Win7...
self.videopanel.Bind(wx.EVT_LEFT_DOWN, self.onVideoPress)
self.videopanel.Bind(wx.EVT_LEFT_UP, self.onVideoRelease)
# trying to bind another way...
#self.Bind(wx.EVT_LEFT_DOWN, self.onVideoPress, self.videopanel)
self.sizer2 = wx.BoxSizer(wx.VERTICAL)
self.sizer2.Add(self.videopanel, 1, flag=wx.EXPAND)
self.SetSizer(self.sizer2)
self.SetMinSize((600, 400))
# finally create the timer.
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.onTimer, self.timer)
self.timer.Start(50)
# VLC player
options = ""
options += "--sub-source marq " # enable the marquee printing
options += "--no-video-title " # not sure if does anything
options += "--verbose=2 " # lots of output (-1 is no output)
self.vlcInstance = vlc.Instance(options) # this lets me write to the VLC marquee...
self.player = self.vlcInstance.media_player_new()
def onVideoPress(self, event):
print "clicked!"
event.Skip()
def onVideoRelease(self, event):
print "mouse released!"
event.Skip()
def onPlay(self, evt):
path = os.path.join(current_directory, "test.mp4")
self.Media = self.vlcInstance.media_new(unicode(path))
self.player.set_media(self.Media)
# VLC receive mouse clicks?
self.player.video_set_mouse_input(0)
# set the window id to render VLC's video output
handle = self.videopanel.GetHandle()
if sys.platform.startswith('linux'): self.player.set_xwindow(handle)
elif sys.platform == "darwin": self.player.set_nsobject(handle)
else: self.player.set_hwnd(handle)
return
def onTimer(self, event):
# on Ubuntu, if I init the video right away it launches in a separate window.
if (time.time() - self.program_launch_time > 1) and not self.video_initted:
self.video_initted=True
self.onPlay(None)
def onExit(self, evt):
os._exit(1)
if __name__ == "__main__":
#app = wx.PySimpleApp()
app = wx.App()
player = Player()
player.Centre()
player.Show()
app.MainLoop()