Bug #963955: Avoid the need to start video twice to just get media length.

This commit is contained in:
Martin Zibricky 2012-10-27 16:52:51 +02:00
parent e1cd3bdd8b
commit b5de3c2828
3 changed files with 43 additions and 30 deletions

View File

@ -106,11 +106,6 @@ class MediaController(object):
AppLocation.get_directory(AppLocation.AppDir), AppLocation.get_directory(AppLocation.AppDir),
u'core', u'ui', u'media') u'core', u'ui', u'media')
for filename in os.listdir(controller_dir): for filename in os.listdir(controller_dir):
# TODO vlc backend is not yet working on Mac OS X.
# For now just ignore vlc backend on Mac OS X.
if sys.platform == 'darwin' and filename == 'vlcplayer.py':
log.warn(u'Disabling vlc media player')
continue
if filename.endswith(u'player.py'): if filename.endswith(u'player.py'):
path = os.path.join(controller_dir, filename) path = os.path.join(controller_dir, filename)
if os.path.isfile(path): if os.path.isfile(path):
@ -294,7 +289,8 @@ class MediaController(object):
""" """
player.resize(display) player.resize(display)
def video(self, controller, file, muted, isBackground, hidden=False): def video(self, controller, file, muted, isBackground, hidden=False,
isInfo=False, controllersVisible=True):
""" """
Loads and starts a video to run with the option of sound Loads and starts a video to run with the option of sound
""" """
@ -352,14 +348,16 @@ class MediaController(object):
elif Settings().value(u'general/auto unblank', elif Settings().value(u'general/auto unblank',
QtCore.QVariant(False)).toBool(): QtCore.QVariant(False)).toBool():
autoplay = True autoplay = True
if autoplay: # Start playback only for visible widgets. If we need just load a video
# and get video information, do not start playback.
if autoplay and not isInfo:
if not self.video_play([controller]): if not self.video_play([controller]):
critical_error_message_box( critical_error_message_box(
translate('MediaPlugin.MediaItem', 'Unsupported File'), translate('MediaPlugin.MediaItem', 'Unsupported File'),
unicode(translate('MediaPlugin.MediaItem', unicode(translate('MediaPlugin.MediaItem',
'Unsupported File'))) 'Unsupported File')))
return False return False
self.set_controls_visible(controller, True) self.set_controls_visible(controller, controllersVisible)
log.debug(u'use %s controller' % self.curDisplayMediaPlayer[display]) log.debug(u'use %s controller' % self.curDisplayMediaPlayer[display])
return True return True

View File

@ -110,33 +110,35 @@ class VlcPlayer(MediaPlayer):
display.vlcWidget = QtGui.QFrame(display) display.vlcWidget = QtGui.QFrame(display)
# creating a basic vlc instance # creating a basic vlc instance
command_line_options = u'--no-video-title-show' command_line_options = u'--no-video-title-show'
if not display.hasAudio: #if not display.hasAudio:
command_line_options += u' --no-audio --no-video-title-show' #command_line_options += u' --no-audio --no-video-title-show'
if Settings().value(u'advanced/hide mouse', #if Settings().value(u'advanced/hide mouse',
QtCore.QVariant(False)).toBool() and \ #QtCore.QVariant(False)).toBool() and \
display.controller.isLive: #display.controller.isLive:
command_line_options += u' --mouse-hide-timeout=0' #command_line_options += u' --mouse-hide-timeout=0'
display.vlcInstance = vlc.Instance(command_line_options) #display.vlcInstance = vlc.Instance(command_line_options)
display.vlcInstance.set_log_verbosity(2) display.vlcInstance = vlc.get_default_instance()
#display.vlcInstance.set_log_verbosity(2)
# creating an empty vlc media player # creating an empty vlc media player
display.vlcMediaPlayer = display.vlcInstance.media_player_new() display.vlcMediaPlayer = display.vlcInstance.media_player_new()
display.vlcWidget.resize(display.size()) display.vlcWidget.resize(display.size())
display.vlcWidget.raise_() display.vlcWidget.raise_()
display.vlcWidget.hide() display.vlcWidget.hide()
# the media player has to be 'connected' to the QFrame # The media player has to be 'connected' to the QFrame.
# (otherwise a video would be displayed in it's own window) # (otherwise a video would be displayed in it's own window)
# this is platform specific! # This is platform specific!
# you have to give the id of the QFrame (or similar object) to # You have to give the id of the QFrame (or similar object)
# vlc, different platforms have different functions for this # to vlc, different platforms have different functions for this.
win_id = int(display.vlcWidget.winId())
if sys.platform == "win32": if sys.platform == "win32":
display.vlcMediaPlayer.set_hwnd(int(display.vlcWidget.winId())) display.vlcMediaPlayer.set_hwnd(win_id)
elif sys.platform == "darwin": elif sys.platform == "darwin":
# We have to use 'set_nsobject' since Qt4 on OSX uses Cocoa # We have to use 'set_nsobject' since Qt4 on OSX uses Cocoa
# framework and not the old Carbon. # framework and not the old Carbon.
display.vlcMediaPlayer.set_nsobject(int(display.vlcWidget.winId())) display.vlcMediaPlayer.set_nsobject(win_id)
else: else:
# for Linux using the X Server # for Linux using the X Server
display.vlcMediaPlayer.set_xwindow(int(display.vlcWidget.winId())) display.vlcMediaPlayer.set_xwindow(win_id)
self.hasOwnWidget = True self.hasOwnWidget = True
def check_available(self): def check_available(self):
@ -156,6 +158,13 @@ class VlcPlayer(MediaPlayer):
# parse the metadata of the file # parse the metadata of the file
display.vlcMedia.parse() display.vlcMedia.parse()
self.volume(display, volume) self.volume(display, volume)
# We need to set media_info.length during load because we want
# to avoid start and stop the video twice. Once for real playback
# and once to just get media length.
#
# Media plugin depends on knowing media length before playback.
controller.media_info.length = \
int(display.vlcMediaPlayer.get_media().get_duration() / 1000)
return True return True
def media_state_wait(self, display, mediaState): def media_state_wait(self, display, mediaState):
@ -212,11 +221,9 @@ class VlcPlayer(MediaPlayer):
display.vlcMediaPlayer.set_time(seekVal) display.vlcMediaPlayer.set_time(seekVal)
def reset(self, display): def reset(self, display):
# FIXME Reset causes that OpenLP stops responding on OS X. display.vlcMediaPlayer.stop()
#display.vlcMediaPlayer.stop() display.vlcWidget.setVisible(False)
#display.vlcWidget.setVisible(False) self.state = MediaState.Off
#self.state = MediaState.Off
pass
def set_visible(self, display, status): def set_visible(self, display, status):
if self.hasOwnWidget: if self.hasOwnWidget:

View File

@ -204,11 +204,19 @@ class MediaMediaItem(MediaManagerItem):
'The file %s no longer exists.')) % filename) 'The file %s no longer exists.')) % filename)
return False return False
self.mediaLength = 0 self.mediaLength = 0
# Get media information and its length.
# TODO This code (mediaController.video()) starts playback but we
# need only media information not video to start. Otherwise
# video is played twice. Find another way to get media info
# without loading and starting video playback.
# TODO Test getting media length with other media backends
# Phonon/Webkit.
if self.plugin.mediaController.video( \ if self.plugin.mediaController.video( \
self.mediaController, filename, False, False): self.mediaController, filename, muted=True,
isBackground=False, isInfo=True, controllersVisible=False):
self.mediaLength = self.mediaController.media_info.length self.mediaLength = self.mediaController.media_info.length
service_item.media_length = self.mediaLength service_item.media_length = self.mediaLength
self.plugin.mediaController.video_reset(self.mediaController) print ' media length:', self.mediaLength
if self.mediaLength > 0: if self.mediaLength > 0:
service_item.add_capability( service_item.add_capability(
ItemCapabilities.HasVariableStartTime) ItemCapabilities.HasVariableStartTime)