forked from openlp/openlp
More cleanups comments and flash removal
This commit is contained in:
parent
360d1155f1
commit
19b6716bea
@ -106,15 +106,15 @@ def set_media_players(players_list, overridden_player='auto'):
|
||||
Settings().setValue('media/players', players)
|
||||
|
||||
|
||||
def parse_optical_path(input):
|
||||
def parse_optical_path(input_string):
|
||||
"""
|
||||
Split the optical path info.
|
||||
|
||||
:param input: The string to parse
|
||||
:param input_string: The string to parse
|
||||
:return: The elements extracted from the string: filename, title, audio_track, subtitle_track, start, end
|
||||
"""
|
||||
log.debug('parse_optical_path, about to parse: "%s"' % input)
|
||||
clip_info = input.split(sep=':')
|
||||
log.debug('parse_optical_path, about to parse: "%s"' % input_string)
|
||||
clip_info = input_string.split(sep=':')
|
||||
title = int(clip_info[1])
|
||||
audio_track = int(clip_info[2])
|
||||
subtitle_track = int(clip_info[3])
|
||||
|
@ -59,6 +59,8 @@ class MediaSlider(QtWidgets.QSlider):
|
||||
def mouseMoveEvent(self, event):
|
||||
"""
|
||||
Override event to allow hover time to be displayed.
|
||||
|
||||
:param event: The triggering event
|
||||
"""
|
||||
time_value = QtWidgets.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width())
|
||||
self.setToolTip('%s' % datetime.timedelta(seconds=int(time_value / 1000)))
|
||||
@ -67,12 +69,16 @@ class MediaSlider(QtWidgets.QSlider):
|
||||
def mousePressEvent(self, event):
|
||||
"""
|
||||
Mouse Press event no new functionality
|
||||
|
||||
:param event: The triggering event
|
||||
"""
|
||||
QtWidgets.QSlider.mousePressEvent(self, event)
|
||||
|
||||
def mouseReleaseEvent(self, event):
|
||||
"""
|
||||
Set the slider position when the mouse is clicked and released on the slider.
|
||||
|
||||
:param event: The triggering event
|
||||
"""
|
||||
self.setValue(QtWidgets.QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width()))
|
||||
QtWidgets.QSlider.mouseReleaseEvent(self, event)
|
||||
@ -350,7 +356,8 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
if self.current_media_players[controller.controller_type] != self.media_players['webkit']:
|
||||
controller.display.set_transparency(False)
|
||||
|
||||
def resize(self, display, player):
|
||||
@staticmethod
|
||||
def resize(display, player):
|
||||
"""
|
||||
After Mainwindow changes or Splitter moved all related media widgets have to be resized
|
||||
|
||||
@ -377,6 +384,8 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
controller.media_info = MediaInfo()
|
||||
controller.media_info.volume = controller.volume_slider.value()
|
||||
controller.media_info.is_background = video_behind_text
|
||||
# background will always loop video.
|
||||
controller.media_info.loop_playback = video_behind_text
|
||||
controller.media_info.file_info = QtCore.QFileInfo(service_item.get_frame_path())
|
||||
display = self._define_display(controller)
|
||||
if controller.is_live:
|
||||
@ -447,10 +456,6 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
:param service_item: The ServiceItem containing the details to be played.
|
||||
"""
|
||||
print('### media_length')
|
||||
# controller = self.display_controllers[DisplayControllerType.Plugin]
|
||||
# print(controller)
|
||||
# stop running videos
|
||||
#self.media_reset(controller)
|
||||
media_info = MediaInfo()
|
||||
media_info.volume = 0
|
||||
media_info.file_info = QtCore.QFileInfo(service_item.get_frame_path())
|
||||
@ -464,7 +469,7 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
print(suffix in player.video_extensions_list)
|
||||
print(suffix in player.audio_extensions_list)
|
||||
print(suffix in player.video_extensions_list or suffix in player.audio_extensions_list)
|
||||
if not suffix in player.video_extensions_list and not suffix in player.audio_extensions_list:
|
||||
if suffix not in player.video_extensions_list and suffix not in player.audio_extensions_list:
|
||||
# Media could not be loaded correctly
|
||||
critical_error_message_box(translate('MediaPlugin.MediaItem', 'Unsupported Media File'),
|
||||
translate('MediaPlugin.MediaItem', 'File %s not supported using player %s') %
|
||||
@ -484,11 +489,11 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
:param title: The main/title track to play.
|
||||
:param audio_track: The audio track to play.
|
||||
:param subtitle_track: The subtitle track to play.
|
||||
:param start: Start position in miliseconds.
|
||||
:param end: End position in miliseconds.
|
||||
:param start: Start position in milliseconds.
|
||||
:param end: End position in milliseconds.
|
||||
:param display: The display to play the media.
|
||||
:param controller: The media contraoller.
|
||||
:return: True if setup succeded else False.
|
||||
:param controller: The media controller.
|
||||
:return: True if setup succeeded else False.
|
||||
"""
|
||||
if controller is None:
|
||||
controller = self.display_controllers[DisplayControllerType.Plugin]
|
||||
@ -533,6 +538,12 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
|
||||
@staticmethod
|
||||
def _get_used_players(service_item):
|
||||
"""
|
||||
Find the player for a given service item
|
||||
|
||||
:param service_item: where the information is about the media and required player
|
||||
:return: player description
|
||||
"""
|
||||
used_players = get_media_players()[0]
|
||||
# If no player, we can't play
|
||||
if not used_players:
|
||||
@ -624,8 +635,10 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
self.media_volume(controller, 0)
|
||||
else:
|
||||
self.media_volume(controller, controller.media_info.volume)
|
||||
print("Status = " + str(status))
|
||||
if status:
|
||||
if not controller.media_info.is_background:
|
||||
print("hello")
|
||||
display.frame.evaluateJavaScript('show_blank("desktop");')
|
||||
self.current_media_players[controller.controller_type].set_visible(display, True)
|
||||
controller.mediabar.actions['playbackPlay'].setVisible(False)
|
||||
@ -656,12 +669,13 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
|
||||
:param controller: The Controller to be processed
|
||||
"""
|
||||
start_again = False
|
||||
if controller.media_info.playing and controller.media_info.length > 0:
|
||||
print("tick", controller.media_info.timer, controller.media_info.length)
|
||||
# print("tick", controller.media_info.timer, controller.media_info.length)
|
||||
if controller.media_info.timer > controller.media_info.length:
|
||||
controller.media_info.timer = controller.media_info.length
|
||||
controller.media_info.timer = controller.media_info.length
|
||||
self.media_stop(controller)
|
||||
if controller.media_info.loop_playback:
|
||||
start_again = True
|
||||
controller.media_info.timer += TICK_TIME
|
||||
seconds = controller.media_info.timer // 1000
|
||||
minutes = seconds // 60
|
||||
@ -671,6 +685,9 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
total_seconds %= 60
|
||||
controller.position_label.setText(' %02d:%02d / %02d:%02d' %
|
||||
(minutes, seconds, total_minutes, total_seconds))
|
||||
if start_again:
|
||||
print("Looooooppppppeeeedd")
|
||||
self.media_play(controller, False)
|
||||
|
||||
def media_pause(self, controller):
|
||||
"""
|
||||
@ -686,6 +703,24 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
controller.mediabar.actions['playbackPause'].setVisible(False)
|
||||
controller.media_info.playing = False
|
||||
|
||||
def media_loop_msg(self, msg):
|
||||
"""
|
||||
Responds to the request to loop a loaded video
|
||||
|
||||
:param msg: First element is the controller which should be used
|
||||
"""
|
||||
self.media_loop(msg[0])
|
||||
|
||||
@staticmethod
|
||||
def media_loop(controller):
|
||||
"""
|
||||
Responds to the request to loop a loaded video
|
||||
|
||||
:param controller: The controller that needs to be stopped
|
||||
"""
|
||||
print('### media_loop')
|
||||
controller.media_info.loop_playback = not controller.media_info.loop_playback
|
||||
|
||||
def media_stop_msg(self, msg):
|
||||
"""
|
||||
Responds to the request to stop a loaded video
|
||||
@ -833,7 +868,8 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
for controller in self.display_controllers:
|
||||
self.media_reset(self.display_controllers[controller])
|
||||
|
||||
def _define_display(self, controller):
|
||||
@staticmethod
|
||||
def _define_display(controller):
|
||||
"""
|
||||
Extract the correct display for a given controller
|
||||
|
||||
|
@ -99,74 +99,6 @@ VIDEO_HTML = """
|
||||
<video id="video" class="size" style="visibility:hidden" autobuffer preload></video>
|
||||
"""
|
||||
|
||||
FLASH_CSS = """
|
||||
#flash {
|
||||
z-index:5;
|
||||
}
|
||||
"""
|
||||
|
||||
FLASH_JS = """
|
||||
function getFlashMovieObject(movieName)
|
||||
{
|
||||
if (window.document[movieName]){
|
||||
return window.document[movieName];
|
||||
}
|
||||
if (document.embeds && document.embeds[movieName]){
|
||||
return document.embeds[movieName];
|
||||
}
|
||||
}
|
||||
|
||||
function show_flash(state, path, volume, variable_value){
|
||||
var text = document.getElementById('flash');
|
||||
var flashMovie = getFlashMovieObject("OpenLPFlashMovie");
|
||||
var src = "src = 'file:///" + path + "'";
|
||||
var view_parm = " wmode='opaque'" + " width='100%%'" + " height='100%%'";
|
||||
var swf_parm = " name='OpenLPFlashMovie'" + " autostart='true' loop='false' play='true'" +
|
||||
" hidden='false' swliveconnect='true' allowscriptaccess='always'" + " volume='" + volume + "'";
|
||||
|
||||
switch(state){
|
||||
case 'load':
|
||||
text.innerHTML = "<embed " + src + view_parm + swf_parm + "/>";
|
||||
flashMovie = getFlashMovieObject("OpenLPFlashMovie");
|
||||
flashMovie.Play();
|
||||
break;
|
||||
case 'play':
|
||||
flashMovie.Play();
|
||||
break;
|
||||
case 'pause':
|
||||
flashMovie.StopPlay();
|
||||
break;
|
||||
case 'stop':
|
||||
flashMovie.StopPlay();
|
||||
tempHtml = text.innerHTML;
|
||||
text.innerHTML = '';
|
||||
text.innerHTML = tempHtml;
|
||||
break;
|
||||
case 'close':
|
||||
flashMovie.StopPlay();
|
||||
text.innerHTML = '';
|
||||
break;
|
||||
case 'length':
|
||||
return flashMovie.TotalFrames();
|
||||
case 'current_time':
|
||||
return flashMovie.CurrentFrame();
|
||||
case 'seek':
|
||||
// flashMovie.GotoFrame(variable_value);
|
||||
break;
|
||||
case 'isEnded':
|
||||
//TODO check flash end
|
||||
return false;
|
||||
case 'setVisible':
|
||||
text.style.visibility = variable_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
FLASH_HTML = """
|
||||
<div id="flash" class="size" style="visibility:hidden"></div>
|
||||
"""
|
||||
|
||||
VIDEO_EXT = ['*.3gp', '*.3gpp', '*.3g2', '*.3gpp2', '*.aac', '*.flv', '*.f4a', '*.f4b', '*.f4p', '*.f4v', '*.mov',
|
||||
'*.m4a', '*.m4b', '*.m4p', '*.m4v', '*.mkv', '*.mp4', '*.ogv', '*.webm', '*.mpg', '*.wmv', '*.mpeg',
|
||||
'*.avi', '*.swf']
|
||||
@ -198,23 +130,25 @@ class WebkitPlayer(MediaPlayer):
|
||||
"""
|
||||
background = QtGui.QColor(Settings().value('players/background color')).name()
|
||||
css = VIDEO_CSS % {'bgcolor': background}
|
||||
return css + FLASH_CSS
|
||||
return css
|
||||
|
||||
def get_media_display_javascript(self):
|
||||
"""
|
||||
Add javascript functions to htmlbuilder
|
||||
"""
|
||||
return VIDEO_JS + FLASH_JS
|
||||
return VIDEO_JS
|
||||
|
||||
def get_media_display_html(self):
|
||||
"""
|
||||
Add html code to htmlbuilder
|
||||
"""
|
||||
return VIDEO_HTML + FLASH_HTML
|
||||
return VIDEO_HTML
|
||||
|
||||
def setup(self, display):
|
||||
"""
|
||||
Set up the player
|
||||
|
||||
:param display: The display to be updated.
|
||||
"""
|
||||
display.web_view.resize(display.size())
|
||||
display.web_view.raise_()
|
||||
@ -235,6 +169,8 @@ class WebkitPlayer(MediaPlayer):
|
||||
def load(self, display):
|
||||
"""
|
||||
Load a video
|
||||
|
||||
:param display: The display to be updated.
|
||||
"""
|
||||
log.debug('load vid in Webkit Controller')
|
||||
controller = display.controller
|
||||
@ -256,24 +192,28 @@ class WebkitPlayer(MediaPlayer):
|
||||
def resize(self, display):
|
||||
"""
|
||||
Resize the player
|
||||
|
||||
:param display: The display to be updated.
|
||||
"""
|
||||
display.web_view.resize(display.size())
|
||||
|
||||
def play(self, display):
|
||||
"""
|
||||
Play a video
|
||||
|
||||
:param display: The display to be updated.
|
||||
"""
|
||||
controller = display.controller
|
||||
display.web_loaded = True
|
||||
length = 0
|
||||
start_time = 0
|
||||
print(self.state, controller.media_info.start_time)
|
||||
if self.state != MediaState.Paused and controller.media_info.start_time > 0:
|
||||
start_time = controller.media_info.start_time
|
||||
self.set_visible(display, True)
|
||||
display.frame.evaluateJavaScript('show_video("play");')
|
||||
if start_time > 0:
|
||||
self.seek(display, controller.media_info.start_time * 1000)
|
||||
# TODO add playing check and get the correct media length
|
||||
print("Webkit play " + str(length))
|
||||
self.state = MediaState.Playing
|
||||
display.web_view.raise_()
|
||||
@ -282,24 +222,28 @@ class WebkitPlayer(MediaPlayer):
|
||||
def pause(self, display):
|
||||
"""
|
||||
Pause a video
|
||||
|
||||
:param display: The display to be updated.
|
||||
"""
|
||||
controller = display.controller
|
||||
display.frame.evaluateJavaScript('show_video("pause");')
|
||||
self.state = MediaState.Paused
|
||||
|
||||
def stop(self, display):
|
||||
"""
|
||||
Stop a video
|
||||
|
||||
:param display: The display to be updated.
|
||||
"""
|
||||
controller = display.controller
|
||||
display.frame.evaluateJavaScript('show_video("stop");')
|
||||
self.state = MediaState.Stopped
|
||||
|
||||
def volume(self, display, volume):
|
||||
"""
|
||||
Set the volume
|
||||
|
||||
:param display: The display to be updated.
|
||||
:param volume: The volume to be set.
|
||||
"""
|
||||
controller = display.controller
|
||||
# 1.0 is the highest value
|
||||
if display.has_audio:
|
||||
vol = float(volume) / float(100)
|
||||
@ -308,6 +252,9 @@ class WebkitPlayer(MediaPlayer):
|
||||
def seek(self, display, seek_value):
|
||||
"""
|
||||
Go to a position in the video
|
||||
|
||||
:param display: The display to be updated.
|
||||
:param seek_value: The value to be set.
|
||||
"""
|
||||
seek = float(seek_value) / 1000
|
||||
display.frame.evaluateJavaScript('show_video("seek", null, null, null, "%f");' % seek)
|
||||
@ -315,16 +262,20 @@ class WebkitPlayer(MediaPlayer):
|
||||
def reset(self, display):
|
||||
"""
|
||||
Reset the player
|
||||
|
||||
:param display: The display to be updated.
|
||||
"""
|
||||
display.frame.evaluateJavaScript('show_video("close");')
|
||||
self.state = MediaState.Off
|
||||
|
||||
def set_visible(self, display, status):
|
||||
def set_visible(self, display, visibility):
|
||||
"""
|
||||
Set the visibility
|
||||
|
||||
:param display: The display to be updated.
|
||||
:param visibility: The visibility to be set.
|
||||
"""
|
||||
controller = display.controller
|
||||
if status:
|
||||
if visibility:
|
||||
is_visible = "visible"
|
||||
else:
|
||||
is_visible = "hidden"
|
||||
@ -333,6 +284,8 @@ class WebkitPlayer(MediaPlayer):
|
||||
def update_ui(self, display):
|
||||
"""
|
||||
Update the UI
|
||||
|
||||
:param display: The display to be updated.
|
||||
"""
|
||||
controller = display.controller
|
||||
if display.frame.evaluateJavaScript('show_video("isEnded");'):
|
||||
@ -346,7 +299,6 @@ class WebkitPlayer(MediaPlayer):
|
||||
if length and length != float('inf'):
|
||||
length = int(length * 1000)
|
||||
if current_time and length:
|
||||
print("webkit update_ui", controller.media_info.length)
|
||||
controller.media_info.length = length
|
||||
controller.seek_slider.setMaximum(length)
|
||||
if not controller.seek_slider.isSliderDown():
|
||||
|
@ -173,7 +173,8 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
|
||||
self.page_layout.addWidget(self.media_widget)
|
||||
self.display_type_combo_box.currentIndexChanged.connect(self.override_player_changed)
|
||||
|
||||
def override_player_changed(self, index):
|
||||
@staticmethod
|
||||
def override_player_changed(index):
|
||||
"""
|
||||
The Player has been overridden
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user