2011-06-05 21:10:49 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2022-02-01 10:10:57 +00:00
|
|
|
# Copyright (c) 2008-2022 OpenLP Developers #
|
2019-04-13 13:00:22 +00:00
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# This program is free software: you can redistribute it and/or modify #
|
|
|
|
# it under the terms of the GNU General Public License as published by #
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, #
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
|
|
|
# GNU General Public License for more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License #
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2013-02-02 06:32:29 +00:00
|
|
|
"""
|
2019-04-12 21:03:23 +00:00
|
|
|
The :mod:`~openlp.core.ui.media.mediacontroller` module is the control module for all media playing.
|
2013-02-02 06:32:29 +00:00
|
|
|
"""
|
2011-06-05 21:10:49 +00:00
|
|
|
import logging
|
2018-10-20 14:41:32 +00:00
|
|
|
|
|
|
|
try:
|
2018-11-04 17:13:56 +00:00
|
|
|
from pymediainfo import MediaInfo
|
2018-10-20 14:41:32 +00:00
|
|
|
pymediainfo_available = True
|
|
|
|
except ImportError:
|
|
|
|
pymediainfo_available = False
|
|
|
|
|
2019-03-24 07:53:19 +00:00
|
|
|
from PyQt5 import QtCore
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2018-10-20 14:41:32 +00:00
|
|
|
from openlp.core.state import State
|
2019-12-07 11:41:30 +00:00
|
|
|
from openlp.core.common import is_linux, is_macosx
|
2018-10-20 14:41:32 +00:00
|
|
|
from openlp.core.common.i18n import translate
|
2017-10-23 22:09:57 +00:00
|
|
|
from openlp.core.common.mixins import LogMixin, RegistryProperties
|
2020-01-12 21:03:40 +00:00
|
|
|
from openlp.core.common.path import path_to_str
|
2017-10-23 22:09:57 +00:00
|
|
|
from openlp.core.common.registry import Registry, RegistryBase
|
2018-08-25 14:08:19 +00:00
|
|
|
from openlp.core.lib.serviceitem import ItemCapabilities
|
2013-01-11 00:19:11 +00:00
|
|
|
from openlp.core.lib.ui import critical_error_message_box
|
2020-03-05 20:35:25 +00:00
|
|
|
from openlp.core.ui import DisplayControllerType, HideMode
|
2020-11-17 03:59:38 +00:00
|
|
|
from openlp.core.ui.media import MediaState, ItemMediaInfo, MediaType, parse_optical_path, parse_stream_path
|
2020-01-27 22:57:58 +00:00
|
|
|
from openlp.core.ui.media.remote import register_views
|
2019-06-11 18:40:20 +00:00
|
|
|
from openlp.core.ui.media.vlcplayer import VlcPlayer, get_vlc
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2015-12-20 21:30:47 +00:00
|
|
|
TICK_TIME = 200
|
2020-11-17 03:59:38 +00:00
|
|
|
HIDE_DELAY_TIME = 2500
|
2015-12-20 21:30:47 +00:00
|
|
|
|
2013-02-02 06:32:29 +00:00
|
|
|
|
2017-10-23 22:09:57 +00:00
|
|
|
class MediaController(RegistryBase, LogMixin, RegistryProperties):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2019-09-21 04:56:43 +00:00
|
|
|
The implementation of the Media Controller which manages how media is played.
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2020-10-04 19:20:10 +00:00
|
|
|
def __init__(self, parent=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
super(MediaController, self).__init__(parent)
|
|
|
|
self.log_info('MediaController Initialising')
|
2018-10-13 10:24:01 +00:00
|
|
|
|
|
|
|
def setup(self):
|
2018-11-04 17:13:56 +00:00
|
|
|
self.vlc_player = None
|
2013-03-06 17:46:19 +00:00
|
|
|
self.current_media_players = {}
|
2011-08-29 19:55:58 +00:00
|
|
|
# Timer for video state
|
2016-02-16 21:14:38 +00:00
|
|
|
self.live_timer = QtCore.QTimer()
|
|
|
|
self.live_timer.setInterval(TICK_TIME)
|
2020-11-17 03:59:38 +00:00
|
|
|
self.live_hide_timer = QtCore.QTimer()
|
|
|
|
self.live_hide_timer.setSingleShot(True)
|
|
|
|
self.live_kill_timer = QtCore.QTimer()
|
|
|
|
self.live_kill_timer.setSingleShot(True)
|
2016-02-16 21:14:38 +00:00
|
|
|
self.preview_timer = QtCore.QTimer()
|
|
|
|
self.preview_timer.setInterval(TICK_TIME)
|
2011-08-29 19:55:58 +00:00
|
|
|
# Signals
|
2020-10-04 19:20:10 +00:00
|
|
|
self.live_timer.timeout.connect(self._media_state_live)
|
2020-11-17 03:59:38 +00:00
|
|
|
self.live_hide_timer.timeout.connect(self._on_media_hide_live)
|
|
|
|
self.live_kill_timer.timeout.connect(self._on_media_kill_live)
|
2020-10-04 19:20:10 +00:00
|
|
|
self.preview_timer.timeout.connect(self._media_state_preview)
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register_function('playbackPlay', self.media_play_msg)
|
|
|
|
Registry().register_function('playbackPause', self.media_pause_msg)
|
|
|
|
Registry().register_function('playbackStop', self.media_stop_msg)
|
2016-02-14 08:38:21 +00:00
|
|
|
Registry().register_function('playbackLoop', self.media_loop_msg)
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register_function('seek_slider', self.media_seek_msg)
|
|
|
|
Registry().register_function('volume_slider', self.media_volume_msg)
|
|
|
|
Registry().register_function('media_hide', self.media_hide)
|
|
|
|
Registry().register_function('media_blank', self.media_blank)
|
|
|
|
Registry().register_function('media_unblank', self.media_unblank)
|
2011-09-28 20:54:43 +00:00
|
|
|
# Signals for background video
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register_function('songs_hide', self.media_hide)
|
2017-06-25 17:03:31 +00:00
|
|
|
Registry().register_function('songs_blank', self.media_blank)
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register_function('songs_unblank', self.media_unblank)
|
2020-01-27 22:57:58 +00:00
|
|
|
register_views()
|
2011-11-24 21:10:37 +00:00
|
|
|
|
2013-12-31 20:29:03 +00:00
|
|
|
def bootstrap_initialise(self):
|
2011-07-10 21:43:07 +00:00
|
|
|
"""
|
2012-10-20 19:52:04 +00:00
|
|
|
Check to see if we have any media Player's available.
|
2011-07-10 21:43:07 +00:00
|
|
|
"""
|
2018-10-13 10:24:01 +00:00
|
|
|
self.setup()
|
2018-11-04 17:13:56 +00:00
|
|
|
self.vlc_player = VlcPlayer(self)
|
2019-04-12 21:03:23 +00:00
|
|
|
State().add_service('mediacontroller', 0)
|
2019-04-20 20:29:12 +00:00
|
|
|
State().add_service('media_live', 0)
|
2019-12-07 11:41:30 +00:00
|
|
|
has_vlc = get_vlc()
|
|
|
|
if has_vlc and pymediainfo_available:
|
2019-04-12 21:03:23 +00:00
|
|
|
State().update_pre_conditions('mediacontroller', True)
|
2019-04-09 16:47:23 +00:00
|
|
|
State().update_pre_conditions('media_live', True)
|
2018-11-04 17:13:56 +00:00
|
|
|
else:
|
2019-01-30 07:18:03 +00:00
|
|
|
if hasattr(self.main_window, 'splash') and self.main_window.splash.isVisible():
|
|
|
|
self.main_window.splash.hide()
|
2019-12-07 11:41:30 +00:00
|
|
|
generic_message = translate('OpenLP.MediaController',
|
|
|
|
'OpenLP requires the following libraries in order to show videos and other '
|
|
|
|
'media, but they are not installed. Please install these libraries to enable '
|
|
|
|
'media playback in OpenLP.')
|
|
|
|
fedora_rpmfusion = translate('OpenLP.MediaController',
|
|
|
|
'To install these libraries, you will need to enable the RPMFusion '
|
|
|
|
'repository: https://rpmfusion.org/')
|
|
|
|
if is_macosx():
|
|
|
|
message = translate('OpenLP.MediaController',
|
|
|
|
'macOS is missing VLC. Please download and install from the VLC web site: '
|
|
|
|
'https://www.videolan.org/vlc/')
|
|
|
|
else:
|
|
|
|
packages = []
|
|
|
|
if not has_vlc:
|
|
|
|
packages.append('python3-vlc')
|
|
|
|
if not pymediainfo_available:
|
|
|
|
packages.append('python3-pymediainfo')
|
|
|
|
message = generic_message + '\n\n' + ', '.join(packages)
|
|
|
|
if not has_vlc and is_linux(distro='fedora'):
|
|
|
|
message += '\n\n' + fedora_rpmfusion
|
|
|
|
State().missing_text('media_live', message)
|
2012-04-28 11:13:16 +00:00
|
|
|
return True
|
2011-07-10 21:43:07 +00:00
|
|
|
|
2019-03-24 07:53:19 +00:00
|
|
|
def bootstrap_post_set_up(self):
|
|
|
|
"""
|
|
|
|
Set up the controllers.
|
|
|
|
:return:
|
|
|
|
"""
|
2019-05-05 05:59:29 +00:00
|
|
|
if State().check_preconditions('mediacontroller'):
|
|
|
|
try:
|
2019-11-03 21:17:47 +00:00
|
|
|
self.setup_display(self.live_controller, False)
|
2019-05-05 05:59:29 +00:00
|
|
|
except AttributeError:
|
|
|
|
State().update_pre_conditions('media_live', False)
|
2019-09-23 20:07:46 +00:00
|
|
|
State().missing_text('media_live', translate(
|
2020-01-12 21:03:40 +00:00
|
|
|
'OpenLP.MediaController', 'No Displays have been configured, so Live Media has been disabled'))
|
2019-11-03 21:17:47 +00:00
|
|
|
self.setup_display(self.preview_controller, True)
|
2019-03-24 07:53:19 +00:00
|
|
|
|
2020-10-04 19:20:10 +00:00
|
|
|
def _display_controllers(self, controller_type):
|
2019-03-24 07:53:19 +00:00
|
|
|
"""
|
|
|
|
Decides which controller to use.
|
|
|
|
|
|
|
|
:param controller_type: The controller type where a player will be placed
|
|
|
|
"""
|
|
|
|
if controller_type == DisplayControllerType.Live:
|
|
|
|
return self.live_controller
|
2019-09-21 04:56:43 +00:00
|
|
|
return self.preview_controller
|
2019-03-24 07:53:19 +00:00
|
|
|
|
2020-10-04 19:20:10 +00:00
|
|
|
def _media_state_live(self):
|
2016-02-21 09:29:16 +00:00
|
|
|
"""
|
|
|
|
Check if there is a running Live media Player and do updating stuff (e.g. update the UI)
|
|
|
|
"""
|
2016-03-07 21:52:09 +00:00
|
|
|
if DisplayControllerType.Live in self.current_media_players:
|
2020-11-17 03:59:38 +00:00
|
|
|
media_player = self.current_media_players[DisplayControllerType.Live]
|
|
|
|
media_player.resize(self.live_controller)
|
|
|
|
media_player.update_ui(self.live_controller, self._define_display(self.live_controller))
|
|
|
|
if not self.tick(self.live_controller):
|
2016-02-21 09:29:16 +00:00
|
|
|
self.live_timer.stop()
|
2016-02-26 16:00:04 +00:00
|
|
|
else:
|
|
|
|
self.live_timer.stop()
|
2020-11-17 03:59:38 +00:00
|
|
|
self.media_stop(self.live_controller)
|
2016-02-16 21:14:38 +00:00
|
|
|
|
2020-10-04 19:20:10 +00:00
|
|
|
def _media_state_preview(self):
|
2016-02-21 09:29:16 +00:00
|
|
|
"""
|
|
|
|
Check if there is a running Preview media Player and do updating stuff (e.g. update the UI)
|
|
|
|
"""
|
2016-03-07 21:52:09 +00:00
|
|
|
if DisplayControllerType.Preview in self.current_media_players:
|
2020-11-17 03:59:38 +00:00
|
|
|
media_player = self.current_media_players[DisplayControllerType.Preview]
|
|
|
|
media_player.resize(self.preview_controller)
|
|
|
|
media_player.update_ui(self.preview_controller, self._define_display(self.preview_controller))
|
|
|
|
if not self.tick(self.preview_controller):
|
2016-02-21 09:29:16 +00:00
|
|
|
self.preview_timer.stop()
|
2011-06-05 21:10:49 +00:00
|
|
|
else:
|
2016-02-26 16:00:04 +00:00
|
|
|
self.preview_timer.stop()
|
2020-11-17 03:59:38 +00:00
|
|
|
self.media_stop(self.preview_controller)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2019-11-03 21:17:47 +00:00
|
|
|
def setup_display(self, controller, preview):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2014-03-17 19:05:55 +00:00
|
|
|
After a new display is configured, all media related widgets will be created too
|
2012-10-13 20:54:56 +00:00
|
|
|
|
2019-11-03 21:17:47 +00:00
|
|
|
:param controller: Display on which the output is to be played
|
2014-03-17 19:05:55 +00:00
|
|
|
:param preview: Whether the display is a main or preview display
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2019-11-03 21:17:47 +00:00
|
|
|
controller.media_info = ItemMediaInfo()
|
|
|
|
controller.has_audio = True
|
2012-10-20 19:52:04 +00:00
|
|
|
if preview:
|
2019-11-03 21:17:47 +00:00
|
|
|
controller.has_audio = False
|
2020-05-18 18:00:40 +00:00
|
|
|
self.vlc_player.setup(controller, self._define_display(controller))
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2019-06-14 17:54:04 +00:00
|
|
|
@staticmethod
|
|
|
|
def set_controls_visible(controller, value):
|
2012-10-13 20:54:56 +00:00
|
|
|
"""
|
2014-03-17 19:05:55 +00:00
|
|
|
After a new display is configured, all media related widget will be created too
|
2012-10-13 20:54:56 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param controller: The controller on which controls act.
|
|
|
|
:param value: control name to be changed.
|
2012-10-13 20:54:56 +00:00
|
|
|
"""
|
2011-06-05 21:10:49 +00:00
|
|
|
# Generic controls
|
|
|
|
controller.mediabar.setVisible(value)
|
|
|
|
|
2016-02-14 15:43:54 +00:00
|
|
|
@staticmethod
|
2019-11-03 21:17:47 +00:00
|
|
|
def resize(controller, player):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2014-03-17 19:05:55 +00:00
|
|
|
After Mainwindow changes or Splitter moved all related media widgets have to be resized
|
2012-10-13 20:54:56 +00:00
|
|
|
|
2019-11-03 21:17:47 +00:00
|
|
|
:param controller: The display on which output is playing.
|
2014-03-17 19:05:55 +00:00
|
|
|
:param player: The player which is doing the playing.
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2019-11-03 21:17:47 +00:00
|
|
|
player.resize(controller)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2019-11-03 21:17:47 +00:00
|
|
|
def load_video(self, source, service_item, hidden=False):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2019-11-03 21:17:47 +00:00
|
|
|
Loads and starts a video to run and sets the stored sound value.
|
2012-10-13 20:54:56 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param source: Where the call originated form
|
|
|
|
:param service_item: The player which is doing the playing
|
|
|
|
:param hidden: The player which is doing the playing
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2018-11-01 20:51:42 +00:00
|
|
|
is_valid = True
|
2020-10-04 19:20:10 +00:00
|
|
|
controller = self._display_controllers(source)
|
2020-11-17 03:59:38 +00:00
|
|
|
log.debug(f'load_video is_live:{controller.is_live}')
|
2011-06-05 21:10:49 +00:00
|
|
|
# stop running videos
|
2012-10-15 18:38:58 +00:00
|
|
|
self.media_reset(controller)
|
2018-11-18 17:29:47 +00:00
|
|
|
controller.media_info = ItemMediaInfo()
|
2020-11-17 03:59:38 +00:00
|
|
|
controller.media_info.media_type = MediaType.Video
|
2019-11-03 21:17:47 +00:00
|
|
|
if controller.is_live:
|
|
|
|
controller.media_info.volume = self.settings.value('media/live volume')
|
|
|
|
else:
|
|
|
|
controller.media_info.volume = self.settings.value('media/preview volume')
|
2016-02-14 15:43:54 +00:00
|
|
|
# background will always loop video.
|
2018-10-21 15:35:59 +00:00
|
|
|
if service_item.is_capable(ItemCapabilities.HasBackgroundAudio):
|
|
|
|
controller.media_info.file_info = service_item.background_audio
|
2020-11-17 03:59:38 +00:00
|
|
|
controller.media_info.media_type = MediaType.Audio
|
|
|
|
# is_background indicates we shouldn't override the normal display
|
|
|
|
controller.media_info.is_background = True
|
2018-10-21 15:35:59 +00:00
|
|
|
else:
|
2020-02-04 20:35:35 +00:00
|
|
|
if service_item.is_capable(ItemCapabilities.HasBackgroundStream):
|
2020-03-08 22:05:09 +00:00
|
|
|
(name, mrl, options) = parse_stream_path(service_item.stream_mrl)
|
2020-02-04 20:35:35 +00:00
|
|
|
controller.media_info.file_info = (mrl, options)
|
|
|
|
controller.media_info.is_background = True
|
|
|
|
controller.media_info.media_type = MediaType.Stream
|
|
|
|
elif service_item.is_capable(ItemCapabilities.HasBackgroundVideo):
|
2020-01-12 21:03:40 +00:00
|
|
|
controller.media_info.file_info = [service_item.video_file_name]
|
|
|
|
service_item.media_length = self.media_length(path_to_str(service_item.video_file_name))
|
|
|
|
controller.media_info.is_looping_playback = True
|
|
|
|
controller.media_info.is_background = True
|
|
|
|
else:
|
|
|
|
controller.media_info.file_info = [service_item.get_frame_path()]
|
2012-10-29 17:25:08 +00:00
|
|
|
display = self._define_display(controller)
|
2013-02-20 20:43:20 +00:00
|
|
|
if controller.is_live:
|
2014-03-04 22:33:50 +00:00
|
|
|
# if this is an optical device use special handling
|
2020-02-04 20:35:35 +00:00
|
|
|
if service_item.is_capable(ItemCapabilities.IsOptical):
|
2020-10-04 19:20:10 +00:00
|
|
|
self.log_debug('video is optical and live')
|
2021-08-28 07:04:15 +00:00
|
|
|
path_string = path_to_str(service_item.get_frame_path())
|
|
|
|
(name, title, audio_track, subtitle_track, start, end, clip_name) = parse_optical_path(path_string)
|
2014-04-22 20:42:07 +00:00
|
|
|
is_valid = self.media_setup_optical(name, title, audio_track, subtitle_track, start, end, display,
|
|
|
|
controller)
|
2020-02-04 20:35:35 +00:00
|
|
|
elif service_item.is_capable(ItemCapabilities.CanStream):
|
2020-10-04 19:20:10 +00:00
|
|
|
self.log_debug('video is stream and live')
|
2020-02-04 20:35:35 +00:00
|
|
|
path = service_item.get_frames()[0]['path']
|
|
|
|
controller.media_info.media_type = MediaType.Stream
|
2020-03-08 22:05:09 +00:00
|
|
|
(name, mrl, options) = parse_stream_path(path)
|
2020-02-04 20:35:35 +00:00
|
|
|
controller.media_info.file_info = (mrl, options)
|
|
|
|
is_valid = self._check_file_type(controller, display)
|
2014-03-26 18:39:54 +00:00
|
|
|
else:
|
2020-10-04 19:20:10 +00:00
|
|
|
self.log_debug('video is not optical or stream, but live')
|
2016-01-24 10:13:33 +00:00
|
|
|
controller.media_info.length = service_item.media_length
|
2021-09-12 08:28:58 +00:00
|
|
|
controller.media_info.start_time = service_item.start_time
|
|
|
|
controller.media_info.timer = service_item.start_time
|
|
|
|
controller.media_info.end_time = service_item.end_time
|
2018-11-18 17:29:47 +00:00
|
|
|
is_valid = self._check_file_type(controller, display)
|
2013-03-04 16:55:13 +00:00
|
|
|
elif controller.preview_display:
|
2020-02-04 20:35:35 +00:00
|
|
|
if service_item.is_capable(ItemCapabilities.IsOptical):
|
2020-10-04 19:20:10 +00:00
|
|
|
self.log_debug('video is optical and preview')
|
2021-08-28 07:04:15 +00:00
|
|
|
path_string = path_to_str(service_item.get_frame_path())
|
|
|
|
(name, title, audio_track, subtitle_track, start, end, clip_name) = parse_optical_path(path_string)
|
2014-04-22 20:42:07 +00:00
|
|
|
is_valid = self.media_setup_optical(name, title, audio_track, subtitle_track, start, end, display,
|
|
|
|
controller)
|
2020-02-04 20:35:35 +00:00
|
|
|
elif service_item.is_capable(ItemCapabilities.CanStream):
|
|
|
|
path = service_item.get_frames()[0]['path']
|
|
|
|
controller.media_info.media_type = MediaType.Stream
|
2020-03-08 22:05:09 +00:00
|
|
|
(name, mrl, options) = parse_stream_path(path)
|
2020-02-04 20:35:35 +00:00
|
|
|
controller.media_info.file_info = (mrl, options)
|
|
|
|
is_valid = self._check_file_type(controller, display)
|
2014-03-26 18:39:54 +00:00
|
|
|
else:
|
2020-10-04 19:20:10 +00:00
|
|
|
self.log_debug('video is not optical or stream, but preview')
|
2016-01-24 10:13:33 +00:00
|
|
|
controller.media_info.length = service_item.media_length
|
2021-09-12 08:28:58 +00:00
|
|
|
controller.media_info.start_time = service_item.start_time
|
|
|
|
controller.media_info.timer = service_item.start_time
|
|
|
|
controller.media_info.end_time = service_item.end_time
|
2018-11-18 17:29:47 +00:00
|
|
|
is_valid = self._check_file_type(controller, display)
|
2013-03-06 22:49:13 +00:00
|
|
|
if not is_valid:
|
2011-08-29 19:55:58 +00:00
|
|
|
# Media could not be loaded correctly
|
2012-12-11 19:55:47 +00:00
|
|
|
critical_error_message_box(translate('MediaPlugin.MediaItem', 'Unsupported File'),
|
2014-03-20 19:10:31 +00:00
|
|
|
translate('MediaPlugin.MediaItem', 'Unsupported File'))
|
2011-07-18 21:25:10 +00:00
|
|
|
return False
|
2020-10-04 19:20:10 +00:00
|
|
|
self.log_debug('video media type: {tpe} '.format(tpe=str(controller.media_info.media_type)))
|
2020-11-17 03:59:38 +00:00
|
|
|
# If both the preview and live view have a stream, make sure only the live view continues streaming
|
|
|
|
if controller.media_info.media_type == MediaType.Stream:
|
|
|
|
if controller.is_live:
|
|
|
|
if self.preview_controller.media_info.media_type == MediaType.Stream:
|
|
|
|
self.log_warning('stream can only be displayed in one instance, killing preview stream')
|
|
|
|
self.preview_controller.on_media_close()
|
|
|
|
else:
|
|
|
|
if self.live_controller.media_info.media_type == MediaType.Stream:
|
|
|
|
self.log_warning('stream cannot be previewed while also streaming live')
|
|
|
|
return
|
2012-09-07 16:58:13 +00:00
|
|
|
autoplay = False
|
2020-11-17 03:59:38 +00:00
|
|
|
if service_item.requires_media() and hidden == HideMode.Theme:
|
2019-06-14 17:54:04 +00:00
|
|
|
autoplay = True
|
2012-09-07 16:58:13 +00:00
|
|
|
# Preview requested
|
2020-11-17 03:59:38 +00:00
|
|
|
elif not controller.is_live:
|
2012-09-07 16:58:13 +00:00
|
|
|
autoplay = True
|
2012-11-04 20:11:10 +00:00
|
|
|
# Visible or background requested or Service Item wants to autostart
|
2022-01-21 21:20:49 +00:00
|
|
|
elif not hidden and service_item.will_auto_start:
|
2012-09-07 16:58:13 +00:00
|
|
|
autoplay = True
|
|
|
|
# Unblank on load set
|
2019-11-03 21:17:47 +00:00
|
|
|
elif self.settings.value('core/auto unblank'):
|
2012-09-07 16:58:13 +00:00
|
|
|
autoplay = True
|
|
|
|
if autoplay:
|
2012-10-26 20:20:23 +00:00
|
|
|
if not self.media_play(controller):
|
2012-12-11 19:55:47 +00:00
|
|
|
critical_error_message_box(translate('MediaPlugin.MediaItem', 'Unsupported File'),
|
2014-03-20 19:10:31 +00:00
|
|
|
translate('MediaPlugin.MediaItem', 'Unsupported File'))
|
2012-09-08 18:29:05 +00:00
|
|
|
return False
|
2021-04-28 06:19:47 +00:00
|
|
|
self._update_seek_ui(controller)
|
2011-12-01 18:07:15 +00:00
|
|
|
self.set_controls_visible(controller, True)
|
2020-10-04 19:20:10 +00:00
|
|
|
self.log_debug('use {nm} controller'.
|
|
|
|
format(nm=self.current_media_players[controller.controller_type].display_name))
|
2011-12-01 18:07:15 +00:00
|
|
|
return True
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2018-03-18 15:33:50 +00:00
|
|
|
@staticmethod
|
2018-10-21 15:35:59 +00:00
|
|
|
def media_length(media_path):
|
2012-09-09 06:54:09 +00:00
|
|
|
"""
|
2018-03-18 15:33:50 +00:00
|
|
|
Uses Media Info to obtain the media length
|
2012-09-14 16:35:07 +00:00
|
|
|
|
2018-11-01 20:51:42 +00:00
|
|
|
:param media_path: The file path to be checked..
|
2012-09-09 06:54:09 +00:00
|
|
|
"""
|
2018-11-04 17:13:56 +00:00
|
|
|
if MediaInfo.can_parse():
|
|
|
|
media_data = MediaInfo.parse(media_path)
|
2020-09-28 21:37:21 +00:00
|
|
|
# duration returns in milli seconds
|
|
|
|
return media_data.tracks[0].duration
|
|
|
|
return 0
|
2012-09-09 06:54:09 +00:00
|
|
|
|
2014-03-04 22:33:50 +00:00
|
|
|
def media_setup_optical(self, filename, title, audio_track, subtitle_track, start, end, display, controller):
|
2014-06-14 21:48:07 +00:00
|
|
|
"""
|
|
|
|
Setup playback of optical media
|
|
|
|
|
|
|
|
:param filename: Path of the optical device/drive.
|
|
|
|
:param title: The main/title track to play.
|
|
|
|
:param audio_track: The audio track to play.
|
|
|
|
:param subtitle_track: The subtitle track to play.
|
2016-02-14 15:43:54 +00:00
|
|
|
:param start: Start position in milliseconds.
|
|
|
|
:param end: End position in milliseconds.
|
2014-06-14 21:48:07 +00:00
|
|
|
:param display: The display to play the media.
|
2016-02-14 15:43:54 +00:00
|
|
|
:param controller: The media controller.
|
|
|
|
:return: True if setup succeeded else False.
|
2014-06-14 21:48:07 +00:00
|
|
|
"""
|
2014-03-04 22:33:50 +00:00
|
|
|
# stop running videos
|
|
|
|
self.media_reset(controller)
|
|
|
|
# Setup media info
|
2018-11-18 17:29:47 +00:00
|
|
|
controller.media_info = ItemMediaInfo()
|
2014-03-04 22:33:50 +00:00
|
|
|
controller.media_info.file_info = QtCore.QFileInfo(filename)
|
2014-05-23 13:39:25 +00:00
|
|
|
if audio_track == -1 and subtitle_track == -1:
|
|
|
|
controller.media_info.media_type = MediaType.CD
|
|
|
|
else:
|
|
|
|
controller.media_info.media_type = MediaType.DVD
|
2017-11-22 21:56:56 +00:00
|
|
|
controller.media_info.start_time = start
|
2020-11-17 03:59:38 +00:00
|
|
|
controller.media_info.timer = start
|
2017-11-22 21:56:56 +00:00
|
|
|
controller.media_info.end_time = end
|
|
|
|
controller.media_info.length = (end - start)
|
2014-03-04 22:33:50 +00:00
|
|
|
controller.media_info.title_track = title
|
|
|
|
controller.media_info.audio_track = audio_track
|
|
|
|
controller.media_info.subtitle_track = subtitle_track
|
|
|
|
# When called from mediaitem display is None
|
|
|
|
if display is None:
|
|
|
|
display = controller.preview_display
|
2020-05-07 05:19:20 +00:00
|
|
|
self.vlc_player.load(controller, display, filename)
|
2019-11-03 21:17:47 +00:00
|
|
|
self.resize(controller, self.vlc_player)
|
2018-11-04 17:13:56 +00:00
|
|
|
self.current_media_players[controller.controller_type] = self.vlc_player
|
2014-03-04 22:33:50 +00:00
|
|
|
return True
|
|
|
|
|
2020-02-04 20:35:35 +00:00
|
|
|
def _check_file_type(self, controller, display):
|
2016-02-13 22:10:11 +00:00
|
|
|
"""
|
|
|
|
Select the correct media Player type from the prioritized Player list
|
|
|
|
|
|
|
|
:param controller: First element is the controller which should be used
|
|
|
|
:param display: Which display to use
|
|
|
|
"""
|
2020-02-04 20:35:35 +00:00
|
|
|
if controller.media_info.media_type == MediaType.Stream:
|
2019-11-03 21:17:47 +00:00
|
|
|
self.resize(controller, self.vlc_player)
|
2020-02-04 20:35:35 +00:00
|
|
|
if self.vlc_player.load(controller, display, controller.media_info.file_info):
|
2019-06-11 19:48:34 +00:00
|
|
|
self.current_media_players[controller.controller_type] = self.vlc_player
|
|
|
|
return True
|
2020-02-04 20:35:35 +00:00
|
|
|
return False
|
2018-11-01 20:51:42 +00:00
|
|
|
for file in controller.media_info.file_info:
|
2020-11-17 03:59:38 +00:00
|
|
|
if not file.is_file and not self.vlc_player.can_folder:
|
|
|
|
return False
|
|
|
|
file = str(file)
|
|
|
|
self.resize(controller, self.vlc_player)
|
|
|
|
if self.vlc_player.load(controller, display, file):
|
|
|
|
self.current_media_players[controller.controller_type] = self.vlc_player
|
|
|
|
return True
|
2011-06-05 21:10:49 +00:00
|
|
|
return False
|
|
|
|
|
2020-11-17 03:59:38 +00:00
|
|
|
def media_play_msg(self, msg):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
Responds to the request to play a loaded video
|
2011-12-03 20:35:53 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param msg: First element is the controller which should be used
|
|
|
|
:param status:
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2020-11-17 03:59:38 +00:00
|
|
|
return self.media_play(msg[0])
|
2012-10-26 20:20:23 +00:00
|
|
|
|
2016-08-08 21:01:09 +00:00
|
|
|
def on_media_play(self):
|
|
|
|
"""
|
|
|
|
Responds to the request to play a loaded video from the web.
|
|
|
|
"""
|
2020-10-04 19:20:10 +00:00
|
|
|
return self.media_play(self.live_controller)
|
2016-08-08 21:01:09 +00:00
|
|
|
|
2020-11-17 03:59:38 +00:00
|
|
|
def media_play(self, controller):
|
2012-10-26 20:20:23 +00:00
|
|
|
"""
|
|
|
|
Responds to the request to play a loaded video
|
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param controller: The controller to be played
|
2012-10-26 20:20:23 +00:00
|
|
|
"""
|
2020-11-17 03:59:38 +00:00
|
|
|
self.log_debug(f'media_play is_live:{controller.is_live}')
|
2013-03-23 07:07:06 +00:00
|
|
|
controller.seek_slider.blockSignals(True)
|
|
|
|
controller.volume_slider.blockSignals(True)
|
2012-10-29 17:25:08 +00:00
|
|
|
display = self._define_display(controller)
|
2019-03-24 07:53:19 +00:00
|
|
|
if not self.current_media_players[controller.controller_type].play(controller, display):
|
2013-03-23 07:07:06 +00:00
|
|
|
controller.seek_slider.blockSignals(False)
|
|
|
|
controller.volume_slider.blockSignals(False)
|
2012-10-29 17:25:08 +00:00
|
|
|
return False
|
2019-11-03 21:17:47 +00:00
|
|
|
self.media_volume(controller, controller.media_info.volume)
|
2020-11-17 03:59:38 +00:00
|
|
|
self._media_set_visibility(controller, True)
|
|
|
|
controller.mediabar.actions['playbackPlay'].setVisible(False)
|
|
|
|
controller.mediabar.actions['playbackPause'].setVisible(True)
|
|
|
|
controller.mediabar.actions['playbackStop'].setDisabled(False)
|
|
|
|
controller.mediabar.actions['playbackLoop'].setChecked(controller.media_info.is_looping_playback)
|
|
|
|
controller.mediabar.actions['playbackStop'].setVisible(not controller.media_info.is_background or
|
|
|
|
controller.media_info.media_type is MediaType.Audio)
|
|
|
|
controller.mediabar.actions['playbackLoop'].setVisible((not controller.media_info.is_background and
|
|
|
|
controller.media_info.media_type is not MediaType.Stream)
|
|
|
|
or controller.media_info.media_type is MediaType.Audio)
|
|
|
|
# Start Timer for ui updates
|
2016-02-14 17:53:16 +00:00
|
|
|
if controller.is_live:
|
2016-02-16 21:14:38 +00:00
|
|
|
if not self.live_timer.isActive():
|
|
|
|
self.live_timer.start()
|
|
|
|
else:
|
|
|
|
if not self.preview_timer.isActive():
|
|
|
|
self.preview_timer.start()
|
2013-03-23 07:07:06 +00:00
|
|
|
controller.seek_slider.blockSignals(False)
|
|
|
|
controller.volume_slider.blockSignals(False)
|
2016-04-13 18:38:49 +00:00
|
|
|
controller.media_info.is_playing = True
|
2020-01-12 21:03:40 +00:00
|
|
|
if not controller.media_info.is_background:
|
2021-02-21 21:17:57 +00:00
|
|
|
display = self._define_display(controller)
|
2020-11-17 03:59:38 +00:00
|
|
|
if controller.is_live:
|
|
|
|
controller.set_hide_mode(None)
|
2021-02-21 21:17:57 +00:00
|
|
|
display.hide_display(HideMode.Screen)
|
2020-03-05 20:35:25 +00:00
|
|
|
controller._set_theme(controller.service_item)
|
|
|
|
display.load_verses([{"verse": "v1", "text": "", "footer": " "}])
|
2020-10-04 19:20:10 +00:00
|
|
|
controller.output_has_changed()
|
2011-08-29 19:55:58 +00:00
|
|
|
return True
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2015-12-20 17:24:45 +00:00
|
|
|
def tick(self, controller):
|
|
|
|
"""
|
|
|
|
Add a tick while the media is playing but only count if not paused
|
|
|
|
|
|
|
|
:param controller: The Controller to be processed
|
2020-11-17 03:59:38 +00:00
|
|
|
:return: Is the video still running?
|
2015-12-20 17:24:45 +00:00
|
|
|
"""
|
2016-02-14 15:43:54 +00:00
|
|
|
start_again = False
|
2020-11-17 03:59:38 +00:00
|
|
|
stopped = False
|
2016-04-13 18:38:49 +00:00
|
|
|
if controller.media_info.is_playing and controller.media_info.length > 0:
|
2021-09-12 08:28:58 +00:00
|
|
|
controller.media_info.timer += TICK_TIME
|
|
|
|
if controller.media_info.timer >= controller.media_info.start_time + controller.media_info.length:
|
2019-11-03 21:17:47 +00:00
|
|
|
if controller.media_info.is_looping_playback:
|
2016-02-14 15:43:54 +00:00
|
|
|
start_again = True
|
2020-03-05 20:35:25 +00:00
|
|
|
else:
|
|
|
|
self.media_stop(controller)
|
2020-11-17 03:59:38 +00:00
|
|
|
stopped = True
|
|
|
|
self._update_seek_ui(controller)
|
|
|
|
else:
|
|
|
|
stopped = True
|
|
|
|
|
2016-02-14 15:43:54 +00:00
|
|
|
if start_again:
|
2021-08-28 07:04:15 +00:00
|
|
|
controller.media_info.timer = controller.media_info.start_time
|
2021-04-28 06:19:47 +00:00
|
|
|
self._update_seek_ui(controller)
|
2020-11-17 03:59:38 +00:00
|
|
|
return not stopped
|
|
|
|
|
|
|
|
def _update_seek_ui(self, controller):
|
2021-09-12 08:28:58 +00:00
|
|
|
seconds = controller.media_info.timer // 1000
|
2020-11-17 03:59:38 +00:00
|
|
|
minutes = seconds // 60
|
|
|
|
seconds %= 60
|
2021-09-12 08:28:58 +00:00
|
|
|
end_seconds = controller.media_info.end_time // 1000
|
|
|
|
end_minutes = end_seconds // 60
|
|
|
|
end_seconds %= 60
|
2020-11-17 03:59:38 +00:00
|
|
|
controller.position_label.setText(' %02d:%02d / %02d:%02d' %
|
2021-09-12 08:28:58 +00:00
|
|
|
(minutes, seconds, end_minutes, end_seconds))
|
2016-02-16 21:14:38 +00:00
|
|
|
|
|
|
|
def media_pause_msg(self, msg):
|
|
|
|
"""
|
|
|
|
Responds to the request to pause a loaded video
|
|
|
|
|
|
|
|
:param msg: First element is the controller which should be used
|
|
|
|
"""
|
2020-06-10 20:10:56 +00:00
|
|
|
return self.media_pause(msg[0])
|
2015-12-20 17:24:45 +00:00
|
|
|
|
2016-08-08 21:01:09 +00:00
|
|
|
def on_media_pause(self):
|
|
|
|
"""
|
|
|
|
Responds to the request to pause a loaded video from the web.
|
|
|
|
"""
|
2020-10-04 19:20:10 +00:00
|
|
|
return self.media_pause(self.live_controller)
|
2016-08-08 21:01:09 +00:00
|
|
|
|
2012-10-26 20:20:23 +00:00
|
|
|
def media_pause(self, controller):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
Responds to the request to pause a loaded video
|
2011-11-24 21:10:37 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param controller: The Controller to be paused
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2020-11-17 03:59:38 +00:00
|
|
|
self.log_debug(f'media_stop is_live:{controller.is_live}')
|
2016-03-08 17:49:57 +00:00
|
|
|
if controller.controller_type in self.current_media_players:
|
2019-11-03 21:17:47 +00:00
|
|
|
self.current_media_players[controller.controller_type].pause(controller)
|
2016-03-08 17:49:57 +00:00
|
|
|
controller.mediabar.actions['playbackPlay'].setVisible(True)
|
|
|
|
controller.mediabar.actions['playbackPause'].setVisible(False)
|
2016-04-13 18:38:49 +00:00
|
|
|
controller.media_info.is_playing = False
|
2020-11-17 03:59:38 +00:00
|
|
|
# Add a tick to the timer to prevent it finishing the video before it can loop back or stop
|
|
|
|
# If the clip finishes, we hit a bug where we cannot start the video
|
|
|
|
controller.media_info.timer += TICK_TIME
|
2020-10-04 19:20:10 +00:00
|
|
|
controller.output_has_changed()
|
2020-06-10 20:10:56 +00:00
|
|
|
return True
|
|
|
|
return False
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2016-02-14 15:43:54 +00:00
|
|
|
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
|
|
|
|
"""
|
2019-11-03 21:17:47 +00:00
|
|
|
controller.media_info.is_looping_playback = not controller.media_info.is_looping_playback
|
|
|
|
controller.mediabar.actions['playbackLoop'].setChecked(controller.media_info.is_looping_playback)
|
2016-02-14 15:43:54 +00:00
|
|
|
|
2012-10-26 20:20:23 +00:00
|
|
|
def media_stop_msg(self, msg):
|
|
|
|
"""
|
|
|
|
Responds to the request to stop a loaded video
|
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param msg: First element is the controller which should be used
|
2012-10-26 20:20:23 +00:00
|
|
|
"""
|
2020-06-10 20:10:56 +00:00
|
|
|
return self.media_stop(msg[0])
|
2012-10-26 20:20:23 +00:00
|
|
|
|
2016-08-08 21:01:09 +00:00
|
|
|
def on_media_stop(self):
|
|
|
|
"""
|
|
|
|
Responds to the request to stop a loaded video from the web.
|
|
|
|
"""
|
2020-10-04 19:20:10 +00:00
|
|
|
return self.media_stop(self.live_controller)
|
2016-08-08 21:01:09 +00:00
|
|
|
|
2019-11-03 21:17:47 +00:00
|
|
|
def media_stop(self, controller):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
Responds to the request to stop a loaded video
|
2011-11-24 21:10:37 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param controller: The controller that needs to be stopped
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2020-11-17 03:59:38 +00:00
|
|
|
self.log_debug(f'media_stop is_live:{controller.is_live}')
|
2013-03-06 17:46:19 +00:00
|
|
|
if controller.controller_type in self.current_media_players:
|
2019-11-03 21:17:47 +00:00
|
|
|
self.current_media_players[controller.controller_type].stop(controller)
|
2020-11-17 03:59:38 +00:00
|
|
|
if controller.is_live:
|
|
|
|
self.live_hide_timer.start(HIDE_DELAY_TIME)
|
|
|
|
if not controller.media_info.is_background:
|
|
|
|
display = self._define_display(controller)
|
|
|
|
if display.hide_mode == HideMode.Screen:
|
2021-04-28 06:19:47 +00:00
|
|
|
Registry().execute('live_display_hide', HideMode.Blank)
|
2020-11-17 03:59:38 +00:00
|
|
|
else:
|
|
|
|
controller.set_hide_mode(display.hide_mode or HideMode.Blank)
|
|
|
|
else:
|
|
|
|
self._media_set_visibility(controller, False)
|
2013-08-31 18:17:38 +00:00
|
|
|
controller.mediabar.actions['playbackPlay'].setVisible(True)
|
2015-03-16 21:32:56 +00:00
|
|
|
controller.mediabar.actions['playbackStop'].setDisabled(True)
|
2013-08-31 18:17:38 +00:00
|
|
|
controller.mediabar.actions['playbackPause'].setVisible(False)
|
2016-04-13 18:38:49 +00:00
|
|
|
controller.media_info.is_playing = False
|
2021-08-28 07:04:15 +00:00
|
|
|
controller.media_info.timer = controller.media_info.start_time
|
2021-09-12 08:28:58 +00:00
|
|
|
controller.seek_slider.setSliderPosition(controller.media_info.start_time)
|
|
|
|
self._update_seek_ui(controller)
|
2020-10-04 19:20:10 +00:00
|
|
|
controller.output_has_changed()
|
2020-06-10 20:10:56 +00:00
|
|
|
return True
|
|
|
|
return False
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2012-12-13 18:55:11 +00:00
|
|
|
def media_volume_msg(self, msg):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
Changes the volume of a running video
|
2011-11-24 21:10:37 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param msg: First element is the controller which should be used
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
controller = msg[0]
|
2011-06-08 14:49:48 +00:00
|
|
|
vol = msg[1][0]
|
2012-12-13 18:55:11 +00:00
|
|
|
self.media_volume(controller, vol)
|
|
|
|
|
|
|
|
def media_volume(self, controller, volume):
|
|
|
|
"""
|
|
|
|
Changes the volume of a running video
|
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param controller: The Controller to use
|
|
|
|
:param volume: The volume to be set
|
2012-12-13 18:55:11 +00:00
|
|
|
"""
|
2020-10-04 19:20:10 +00:00
|
|
|
self.log_debug(f'media_volume {volume}')
|
2019-11-03 21:17:47 +00:00
|
|
|
if controller.is_live:
|
|
|
|
self.settings.setValue('media/live volume', volume)
|
|
|
|
else:
|
|
|
|
self.settings.setValue('media/preview volume', volume)
|
|
|
|
controller.media_info.volume = volume
|
|
|
|
self.current_media_players[controller.controller_type].volume(controller, volume)
|
2013-03-23 07:07:06 +00:00
|
|
|
controller.volume_slider.setValue(volume)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2012-12-29 20:54:25 +00:00
|
|
|
def media_seek_msg(self, msg):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2013-03-23 07:07:06 +00:00
|
|
|
Responds to the request to change the seek Slider of a loaded video via a message
|
2011-11-24 21:10:37 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param msg: First element is the controller which should be used
|
2013-03-23 07:07:06 +00:00
|
|
|
Second element is a list with the seek value as first element
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
controller = msg[0]
|
2013-03-23 07:07:06 +00:00
|
|
|
seek_value = msg[1][0]
|
|
|
|
self.media_seek(controller, seek_value)
|
2012-12-29 20:54:25 +00:00
|
|
|
|
2013-03-23 07:07:06 +00:00
|
|
|
def media_seek(self, controller, seek_value):
|
2012-12-29 20:54:25 +00:00
|
|
|
"""
|
|
|
|
Responds to the request to change the seek Slider of a loaded video
|
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param controller: The controller to use.
|
|
|
|
:param seek_value: The value to set.
|
2012-12-29 20:54:25 +00:00
|
|
|
"""
|
2021-09-12 08:28:58 +00:00
|
|
|
# This may be triggered by setting the slider max/min before the current_media_players dict is set
|
|
|
|
if controller.controller_type in self.current_media_players:
|
|
|
|
self.current_media_players[controller.controller_type].seek(controller, seek_value)
|
|
|
|
controller.media_info.timer = seek_value
|
|
|
|
self._update_seek_ui(controller)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2020-11-17 03:59:38 +00:00
|
|
|
def media_reset(self, controller, delayed=False):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
Responds to the request to reset a loaded video
|
2015-12-20 17:24:45 +00:00
|
|
|
:param controller: The controller to use.
|
2020-11-17 03:59:38 +00:00
|
|
|
:param delayed: Should the controller briefly remain visible.
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2020-11-17 03:59:38 +00:00
|
|
|
self.log_debug('media_reset')
|
2012-01-11 20:51:11 +00:00
|
|
|
self.set_controls_visible(controller, False)
|
2013-03-06 17:46:19 +00:00
|
|
|
if controller.controller_type in self.current_media_players:
|
2019-11-03 21:17:47 +00:00
|
|
|
self.current_media_players[controller.controller_type].reset(controller)
|
2020-11-17 03:59:38 +00:00
|
|
|
if controller.is_live and delayed:
|
|
|
|
self.live_kill_timer.start(HIDE_DELAY_TIME)
|
|
|
|
else:
|
|
|
|
if controller.is_live:
|
|
|
|
self.live_kill_timer.stop()
|
|
|
|
else:
|
|
|
|
self._media_set_visibility(controller, False)
|
|
|
|
del self.current_media_players[controller.controller_type]
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2020-11-17 03:59:38 +00:00
|
|
|
def media_hide_msg(self, msg):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
Hide the related video Widget
|
2011-11-24 21:10:37 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param msg: First element is the boolean for Live indication
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2013-02-20 20:43:20 +00:00
|
|
|
is_live = msg[1]
|
2020-11-17 03:59:38 +00:00
|
|
|
self.media_hide(is_live)
|
|
|
|
|
|
|
|
def media_hide(self, is_live, delayed=False):
|
|
|
|
"""
|
|
|
|
Pause and hide the related video Widget if is_live
|
|
|
|
|
|
|
|
:param is_live: Live indication
|
|
|
|
:param delayed: Should the controller briefly remain visible.
|
|
|
|
"""
|
|
|
|
self.log_debug(f'media_hide is_live:{is_live}')
|
|
|
|
if not is_live or self.live_kill_timer.isActive():
|
2012-04-28 11:13:16 +00:00
|
|
|
return
|
2013-03-06 17:46:19 +00:00
|
|
|
if self.live_controller.controller_type in self.current_media_players and \
|
2016-02-26 16:00:04 +00:00
|
|
|
self.current_media_players[self.live_controller.controller_type].get_live_state() == MediaState.Playing:
|
2020-11-17 03:59:38 +00:00
|
|
|
if delayed:
|
|
|
|
self.live_hide_timer.start(HIDE_DELAY_TIME)
|
|
|
|
else:
|
|
|
|
self.media_pause(self.live_controller)
|
|
|
|
self._media_set_visibility(self.live_controller, False)
|
|
|
|
|
|
|
|
def _on_media_hide_live(self):
|
|
|
|
self.media_pause(self.live_controller)
|
|
|
|
self._media_set_visibility(self.live_controller, False)
|
|
|
|
|
|
|
|
def _on_media_kill_live(self):
|
|
|
|
self._media_set_visibility(self.live_controller, False)
|
|
|
|
del self.current_media_players[self.live_controller.controller_type]
|
|
|
|
|
|
|
|
def _media_set_visibility(self, controller, visible):
|
|
|
|
"""
|
|
|
|
Set the live video Widget visibility
|
|
|
|
"""
|
|
|
|
if controller.is_live:
|
|
|
|
self.live_hide_timer.stop()
|
|
|
|
visible = visible and controller.media_info.media_type is not MediaType.Audio
|
|
|
|
self.current_media_players[controller.controller_type].set_visible(controller, visible)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2012-10-15 18:38:58 +00:00
|
|
|
def media_blank(self, msg):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
Blank the related video Widget
|
2011-11-24 21:10:37 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param msg: First element is the boolean for Live indication
|
2011-11-24 21:10:37 +00:00
|
|
|
Second element is the hide mode
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2013-02-20 20:43:20 +00:00
|
|
|
is_live = msg[1]
|
2011-10-24 20:04:29 +00:00
|
|
|
hide_mode = msg[2]
|
2020-11-17 03:59:38 +00:00
|
|
|
self.log_debug(f'media_blank is_live:{is_live}')
|
|
|
|
if not is_live or self.live_controller.controller_type not in self.current_media_players:
|
2012-04-28 11:13:16 +00:00
|
|
|
return
|
2020-11-17 03:59:38 +00:00
|
|
|
if self.live_kill_timer.isActive():
|
|
|
|
# If pressing blank when the video is being removed, remove it instantly
|
|
|
|
self._media_set_visibility(self.live_controller, False)
|
|
|
|
self.media_reset(self.live_controller)
|
|
|
|
return
|
|
|
|
if not self.live_controller.media_info.is_background:
|
|
|
|
Registry().execute('live_display_hide', hide_mode)
|
|
|
|
controller_type = self.live_controller.controller_type
|
|
|
|
playing = self.current_media_players[controller_type].get_live_state() == MediaState.Playing
|
|
|
|
if hide_mode == HideMode.Theme:
|
|
|
|
if not playing:
|
|
|
|
self.media_play(self.live_controller)
|
|
|
|
else:
|
|
|
|
self.live_hide_timer.stop()
|
|
|
|
else:
|
|
|
|
if hide_mode == HideMode.Screen:
|
|
|
|
if playing:
|
|
|
|
self.media_pause(self.live_controller)
|
|
|
|
self._media_set_visibility(self.live_controller, False)
|
|
|
|
else:
|
|
|
|
self.live_hide_timer.start(HIDE_DELAY_TIME)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2012-10-15 18:38:58 +00:00
|
|
|
def media_unblank(self, msg):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
Unblank the related video Widget
|
2011-11-24 21:10:37 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param msg: First element is not relevant in this context
|
2011-11-24 21:10:37 +00:00
|
|
|
Second element is the boolean for Live indication
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2013-02-20 20:43:20 +00:00
|
|
|
is_live = msg[1]
|
2020-11-17 03:59:38 +00:00
|
|
|
self.log_debug(f'media_blank is_live:{is_live}')
|
|
|
|
if not is_live or self.live_kill_timer.isActive():
|
2012-04-28 11:13:16 +00:00
|
|
|
return
|
2020-11-17 03:59:38 +00:00
|
|
|
Registry().execute('live_display_show')
|
|
|
|
if self.live_controller.controller_type in self.current_media_players:
|
|
|
|
if self.current_media_players[self.live_controller.controller_type].get_live_state() != \
|
|
|
|
MediaState.Playing:
|
|
|
|
self.media_play(self.live_controller)
|
|
|
|
else:
|
|
|
|
self._media_set_visibility(self.live_controller, True)
|
|
|
|
if not self.live_controller.media_info.is_background:
|
|
|
|
display = self._define_display(self.live_controller)
|
|
|
|
display.hide_display(HideMode.Screen)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2011-07-20 21:16:36 +00:00
|
|
|
def finalise(self):
|
2013-02-02 06:32:29 +00:00
|
|
|
"""
|
|
|
|
Reset all the media controllers when OpenLP shuts down
|
|
|
|
"""
|
2016-02-16 21:14:38 +00:00
|
|
|
self.live_timer.stop()
|
2020-11-17 03:59:38 +00:00
|
|
|
self.live_hide_timer.stop()
|
|
|
|
self.live_kill_timer.stop()
|
2016-02-16 21:14:38 +00:00
|
|
|
self.preview_timer.stop()
|
2020-10-04 19:20:10 +00:00
|
|
|
self.media_reset(self._display_controllers(DisplayControllerType.Live))
|
|
|
|
self.media_reset(self._display_controllers(DisplayControllerType.Preview))
|
2012-10-29 17:25:08 +00:00
|
|
|
|
2016-02-14 15:43:54 +00:00
|
|
|
@staticmethod
|
|
|
|
def _define_display(controller):
|
2012-10-29 17:25:08 +00:00
|
|
|
"""
|
|
|
|
Extract the correct display for a given controller
|
2012-10-31 18:27:24 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param controller: Controller to be used
|
2012-10-29 17:25:08 +00:00
|
|
|
"""
|
2013-02-20 20:43:20 +00:00
|
|
|
if controller.is_live:
|
2012-10-29 17:25:08 +00:00
|
|
|
return controller.display
|
2013-02-20 20:43:20 +00:00
|
|
|
return controller.preview_display
|