I'm playing around with python & libVLC 1.1 bindings to create a minimalistic home box office app that will listen to lirc remote and play all sorts of media.. This is on Ubuntu 10.10.
The problem I'm seeing is with fullscreen. Reading the viewtopic.php?f=32&t=77936 topic I see that it can be done, I'm not sure how and what is the nett result.
This is player class I've come up with, using the qtvlc.py as basis - use QFrame to embed the VLC media player:
Code: Select all
class VLCPlayer(QtGui.QWidget):
def __init__(self, parent = None, video_frame = None):
QtGui.QWidget.__init__(self, parent)
# Creating a basic VLC instance
self.vlc_instance = vlc.Instance()
self.vlc_instance.set_log_verbosity(3)
self.vlc_log = self.vlc_instance.log_open()
print "VLC verbosity : %d" % self.vlc_instance.get_log_verbosity()
print "VLC msg count : %d" % self.vlc_log.count()
# Creating an empty VLC media player
self.media_player = self.vlc_instance.media_player_new()
self.is_paused = False
self.video_frame = video_frame
def open(self, mrl, stream = False):
if not mrl:
return
print "opening MRL %s .." % mrl
# Create the media
if stream:
self.media = self.vlc_instance.media_new_location(unicode(mrl))
else:
self.media = self.vlc_instance.media_new(unicode(mrl))
print "MEdia: %s " % type(self.media)
# Put the media in the media player
self.media_player.set_media(self.media)
print "MEdia2: %s " % type(self.media)
print "Media MRL: %s" % self.media.get_mrl()
print "media state %s" % self.media.get_state()
# Parse the metadata of the file
if not stream:
self.media.parse()
# the media player has to be 'connected' to the QFrame
# (otherwise a video would be displayed in it's own window)
# this is platform specific!
# you have to give the id of the QFrame (or similar object) to
# vlc, different platforms have different functions for this
if self.video_frame:
if sys.platform == "linux2": # for Linux using the X Server
self.media_player.set_xwindow(self.video_frame.winId())
elif sys.platform == "win32": # for Windows
self.media_player.set_hwnd(self.video_frame.winId())
elif sys.platform == "darwin": # for MacOS
self.media_player.set_agl(self.video_frame.windId())
self.play_pause()
def set_fullscreen(self, root, mode = False):
old_mode = self.media_player.get_fullscreen()
new_mode = int(mode)
print "self.video_frame: %s" % self.video_frame.winId()
self.media_player.set_fullscreen(new_mode)
if new_mode:
print "FULLSCREEN"
# New frame for fullscreen
full = QtGui.QFrame()
self.media_player.set_xwindow(full.winId())
print "full: %s" % full.winId()
else:
print "EMBED"
self.media_player.set_xwindow(self.video_frame.winId())
def play_pause(self):
print "play_pause.."
if self.media_player.is_playing():
self.media_player.pause()
self.is_paused = True
else:
self.media_player.play()
self.is_paused = False
print "VLC msg count : %d" % self.vlc_log.count()
def stop(self):
print "stop.."
self.media_player.stop()
Behaviour:
- I can 'see' the change of fullscreen ON/OFF after stopping the playback,
- when changing to fullscreen OFF, VLC output appears in new window , instead of previously used QFrame (self.video_frame), also playback is restarted at this point. If I stop the playback the VLC output appears in QFrame (self.video_frame) as expected.
What is the best way to 'fix' this behavior to: smooth fullscreen on/off transition without stopping playback
Do I need to fiddle with:
- fullscreen mode change
- get playtime, save it
- stop the playback
- [fullscreen transition seen]
- start the playback
- seek to saved playtime
- carry on playing
Thanx!