Esempio n. 1
0
    def media_length(self, service_item):
        """
        Loads and starts a media item to obtain the media length

        :param service_item: The ServiceItem containing the details to be played.
        """
        media_info = MediaInfo()
        media_info.volume = 0
        media_info.file_info = QtCore.QFileInfo(service_item.get_frame_path())
        # display = controller.preview_display
        suffix = '*.%s' % media_info.file_info.suffix().lower()
        used_players = get_media_players()[0]
        player = self.media_players[used_players[0]]
        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') %
                (service_item.get_frame_path(), used_players[0]))
            return False
        media_data = MediaInfoWrapper.parse(service_item.get_frame_path())
        # duration returns in milli seconds
        service_item.set_media_length(media_data.tracks[0].duration)
        return True
Esempio n. 2
0
    def media_length(service_item):
        """
        Uses Media Info to obtain the media length

        :param service_item: The ServiceItem containing the details to be played.
        """
        media_info = MediaInfo()
        media_info.volume = 0
        media_info.file_info = QtCore.QFileInfo(service_item.get_frame_path())
        media_data = MediaInfoWrapper.parse(service_item.get_frame_path())
        # duration returns in milli seconds
        service_item.set_media_length(media_data.tracks[0].duration)
        return True
Esempio n. 3
0
    def media_length(self, service_item):
        """
        Loads and starts a media item to obtain the media length

        :param service_item: The ServiceItem containing the details to be played.
        """
        controller = self.display_controllers[DisplayControllerType.Plugin]
        log.debug('media_length')
        # stop running videos
        self.media_reset(controller)
        controller.media_info = MediaInfo()
        controller.media_info.volume = 0
        controller.media_info.file_info = QtCore.QFileInfo(
            service_item.get_frame_path())
        display = controller.preview_display
        if not self._check_file_type(controller, display, service_item):
            # Media could not be loaded correctly
            critical_error_message_box(
                translate('MediaPlugin.MediaItem', 'Unsupported File'),
                translate('MediaPlugin.MediaItem', 'Unsupported File'))
            return False
        if not self.media_play(controller):
            critical_error_message_box(
                translate('MediaPlugin.MediaItem', 'Unsupported File'),
                translate('MediaPlugin.MediaItem', 'Unsupported File'))
            return False
        service_item.set_media_length(controller.media_info.length)
        self.media_stop(controller)
        log.debug('use %s controller' %
                  self.current_media_players[controller.controller_type])
        return True
Esempio n. 4
0
    def setup_generic_controls(self, controller):
        """
        Set up controls on the control_panel for a given controller

        :param controller:  First element is the controller which should be used
        """
        controller.media_info = MediaInfo()
        # Build a Media ToolBar
        controller.mediabar = OpenLPToolbar(controller)
        controller.mediabar.add_toolbar_action(
            'playbackPlay',
            text='media_playback_play',
            icon=':/slides/media_playback_start.png',
            tooltip=translate('OpenLP.SlideController',
                              'Start playing media.'),
            triggers=controller.send_to_plugins)
        controller.mediabar.add_toolbar_action(
            'playbackPause',
            text='media_playback_pause',
            icon=':/slides/media_playback_pause.png',
            tooltip=translate('OpenLP.SlideController',
                              'Pause playing media.'),
            triggers=controller.send_to_plugins)
        controller.mediabar.add_toolbar_action(
            'playbackStop',
            text='media_playback_stop',
            icon=':/slides/media_playback_stop.png',
            tooltip=translate('OpenLP.SlideController', 'Stop playing media.'),
            triggers=controller.send_to_plugins)
        # Build the seek_slider.
        controller.seek_slider = MediaSlider(QtCore.Qt.Horizontal, self,
                                             controller)
        controller.seek_slider.setMaximum(1000)
        controller.seek_slider.setTracking(True)
        controller.seek_slider.setMouseTracking(True)
        controller.seek_slider.setToolTip(
            translate('OpenLP.SlideController', 'Video position.'))
        controller.seek_slider.setGeometry(QtCore.QRect(90, 260, 221, 24))
        controller.seek_slider.setObjectName('seek_slider')
        controller.mediabar.add_toolbar_widget(controller.seek_slider)
        # Build the volume_slider.
        controller.volume_slider = QtGui.QSlider(QtCore.Qt.Horizontal)
        controller.volume_slider.setTickInterval(10)
        controller.volume_slider.setTickPosition(QtGui.QSlider.TicksAbove)
        controller.volume_slider.setMinimum(0)
        controller.volume_slider.setMaximum(100)
        controller.volume_slider.setTracking(True)
        controller.volume_slider.setToolTip(
            translate('OpenLP.SlideController', 'Audio Volume.'))
        controller.volume_slider.setValue(controller.media_info.volume)
        controller.volume_slider.setGeometry(QtCore.QRect(90, 160, 221, 24))
        controller.volume_slider.setObjectName('volume_slider')
        controller.mediabar.add_toolbar_widget(controller.volume_slider)
        controller.controller_layout.addWidget(controller.mediabar)
        controller.mediabar.setVisible(False)
        # Signals
        controller.seek_slider.valueChanged.connect(controller.send_to_plugins)
        controller.volume_slider.valueChanged.connect(
            controller.send_to_plugins)
Esempio n. 5
0
    def media_setup_optical(self, filename, title, audio_track, subtitle_track,
                            start, end, display, controller):
        """
        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.
        :param start: Start position in miliseconds.
        :param end: End position in miliseconds.
        :param display: The display to play the media.
        :param controller: The media contraoller.
        :return: True if setup succeded else False.
        """
        log.debug('media_setup_optical')
        if controller is None:
            controller = self.display_controllers[DisplayControllerType.Plugin]
        # stop running videos
        self.media_reset(controller)
        # Setup media info
        controller.media_info = MediaInfo()
        controller.media_info.file_info = QtCore.QFileInfo(filename)
        if audio_track == -1 and subtitle_track == -1:
            controller.media_info.media_type = MediaType.CD
        else:
            controller.media_info.media_type = MediaType.DVD
        controller.media_info.start_time = start / 1000
        controller.media_info.end_time = end / 1000
        controller.media_info.length = (end - start) / 1000
        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
        # Find vlc player
        used_players = get_media_players()[0]
        vlc_player = None
        for title in used_players:
            player = self.media_players[title]
            if player.name == 'vlc':
                vlc_player = player
        if vlc_player is None:
            critical_error_message_box(
                translate('MediaPlugin.MediaItem', 'VLC player required'),
                translate(
                    'MediaPlugin.MediaItem',
                    'VLC player required for playback of optical devices'))
            return False
        vlc_player.load(display)
        self.resize(display, vlc_player)
        self.current_media_players[controller.controller_type] = vlc_player
        if audio_track == -1 and subtitle_track == -1:
            controller.media_info.media_type = MediaType.CD
        else:
            controller.media_info.media_type = MediaType.DVD
        return True
Esempio n. 6
0
    def media_length(self, service_item):
        """
        Loads and starts a media item to obtain the media length

        :param service_item: The ServiceItem containing the details to be played.
        """
        media_info = MediaInfo()
        media_info.volume = 0
        media_info.file_info = QtCore.QFileInfo(service_item.get_frame_path())
        # display = controller.preview_display
        suffix = '*.%s' % media_info.file_info.suffix().lower()
        used_players = get_media_players()[0]
        player = self.media_players[used_players[0]]
        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') %
                                       (service_item.get_frame_path(), used_players[0]))
            return False
        media_data = MediaInfoWrapper.parse(service_item.get_frame_path())
        # duration returns in milli seconds
        service_item.set_media_length(media_data.tracks[0].duration)
        return True
Esempio n. 7
0
    def video(self,
              source,
              service_item,
              hidden=False,
              video_behind_text=False):
        """
        Loads and starts a video to run with the option of sound

        :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
        :param video_behind_text: Is the video to be played behind text.
        """
        is_valid = False
        controller = self.display_controllers[source]
        # stop running videos
        self.media_reset(controller)
        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.can_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:
            # if this is an optical device use special handling
            if service_item.is_capable(ItemCapabilities.IsOptical):
                log.debug('video is optical and live')
                path = service_item.get_frame_path()
                (name, title, audio_track, subtitle_track, start, end,
                 clip_name) = parse_optical_path(path)
                is_valid = self.media_setup_optical(name, title, audio_track,
                                                    subtitle_track, start, end,
                                                    display, controller)
            else:
                log.debug('video is not optical and live')
                controller.media_info.length = service_item.media_length
                is_valid = self._check_file_type(controller, display,
                                                 service_item)
            display.override['theme'] = ''
            display.override['video'] = True
            if controller.media_info.is_background:
                # ignore start/end time
                controller.media_info.start_time = 0
                controller.media_info.end_time = 0
            else:
                controller.media_info.start_time = service_item.start_time
                controller.media_info.end_time = service_item.end_time
        elif controller.preview_display:
            if service_item.is_capable(ItemCapabilities.IsOptical):
                log.debug('video is optical and preview')
                path = service_item.get_frame_path()
                (name, title, audio_track, subtitle_track, start, end,
                 clip_name) = parse_optical_path(path)
                is_valid = self.media_setup_optical(name, title, audio_track,
                                                    subtitle_track, start, end,
                                                    display, controller)
            else:
                log.debug('video is not optical and preview')
                controller.media_info.length = service_item.media_length
                is_valid = self._check_file_type(controller, display,
                                                 service_item)
        if not is_valid:
            # Media could not be loaded correctly
            critical_error_message_box(
                translate('MediaPlugin.MediaItem', 'Unsupported File'),
                translate('MediaPlugin.MediaItem', 'Unsupported File'))
            return False
        log.debug('video mediatype: ' + str(controller.media_info.media_type))
        # dont care about actual theme, set a black background
        if controller.is_live and not controller.media_info.is_background:
            display.frame.evaluateJavaScript(
                'show_video("setBackBoard", null, null,"visible");')
        # now start playing - Preview is autoplay!
        autoplay = False
        # Preview requested
        if not controller.is_live:
            autoplay = True
        # Visible or background requested or Service Item wants to autostart
        elif not hidden or controller.media_info.is_background or service_item.will_auto_start:
            autoplay = True
        # Unblank on load set
        elif Settings().value('core/auto unblank'):
            autoplay = True
        if autoplay:
            if not self.media_play(controller):
                critical_error_message_box(
                    translate('MediaPlugin.MediaItem', 'Unsupported File'),
                    translate('MediaPlugin.MediaItem', 'Unsupported File'))
                return False
        self.set_controls_visible(controller, True)
        log.debug(
            'use %s controller' %
            self.current_media_players[controller.controller_type].display_name
        )
        return True
Esempio n. 8
0
    def setup_generic_controls(self, controller):
        """
        Set up controls on the control_panel for a given controller

        :param controller:  First element is the controller which should be used
        """
        controller.media_info = MediaInfo()
        # Build a Media ToolBar
        controller.mediabar = OpenLPToolbar(controller)
        controller.mediabar.add_toolbar_action(
            'playbackPlay',
            text='media_playback_play',
            icon=UiIcons().play,
            tooltip=translate('OpenLP.SlideController',
                              'Start playing media.'),
            triggers=controller.send_to_plugins)
        controller.mediabar.add_toolbar_action(
            'playbackPause',
            text='media_playback_pause',
            icon=UiIcons().pause,
            tooltip=translate('OpenLP.SlideController',
                              'Pause playing media.'),
            triggers=controller.send_to_plugins)
        controller.mediabar.add_toolbar_action(
            'playbackStop',
            text='media_playback_stop',
            icon=UiIcons().stop,
            tooltip=translate('OpenLP.SlideController', 'Stop playing media.'),
            triggers=controller.send_to_plugins)
        controller.mediabar.add_toolbar_action(
            'playbackLoop',
            text='media_playback_loop',
            icon=UiIcons().repeat,
            checked=False,
            tooltip=translate('OpenLP.SlideController', 'Loop playing media.'),
            triggers=controller.send_to_plugins)
        controller.position_label = QtWidgets.QLabel()
        controller.position_label.setText(' 00:00 / 00:00')
        controller.position_label.setAlignment(QtCore.Qt.AlignRight
                                               | QtCore.Qt.AlignVCenter)
        controller.position_label.setToolTip(
            translate('OpenLP.SlideController', 'Video timer.'))
        controller.position_label.setMinimumSize(90, 0)
        controller.position_label.setObjectName('position_label')
        controller.mediabar.add_toolbar_widget(controller.position_label)
        # Build the seek_slider.
        controller.seek_slider = MediaSlider(QtCore.Qt.Horizontal, self,
                                             controller)
        controller.seek_slider.setMaximum(1000)
        controller.seek_slider.setTracking(True)
        controller.seek_slider.setMouseTracking(True)
        controller.seek_slider.setToolTip(
            translate('OpenLP.SlideController', 'Video position.'))
        controller.seek_slider.setGeometry(QtCore.QRect(90, 260, 221, 24))
        controller.seek_slider.setObjectName('seek_slider')
        controller.mediabar.add_toolbar_widget(controller.seek_slider)
        # Build the volume_slider.
        controller.volume_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
        controller.volume_slider.setTickInterval(10)
        controller.volume_slider.setTickPosition(QtWidgets.QSlider.TicksAbove)
        controller.volume_slider.setMinimum(0)
        controller.volume_slider.setMaximum(100)
        controller.volume_slider.setTracking(True)
        controller.volume_slider.setToolTip(
            translate('OpenLP.SlideController', 'Audio Volume.'))
        controller.volume_slider.setValue(controller.media_info.volume)
        controller.volume_slider.setGeometry(QtCore.QRect(90, 160, 221, 24))
        controller.volume_slider.setObjectName('volume_slider')
        controller.mediabar.add_toolbar_widget(controller.volume_slider)
        controller.controller_layout.addWidget(controller.mediabar)
        controller.mediabar.setVisible(False)
        if not controller.is_live:
            controller.volume_slider.setEnabled(False)
        # Signals
        controller.seek_slider.valueChanged.connect(controller.send_to_plugins)
        controller.volume_slider.valueChanged.connect(
            controller.send_to_plugins)