Beispiel #1
0
 def set_event_context(self):
     """
     Set the event context
     """
     context = self.event_context
     if self.menustack and hasattr(self.menustack[-1], 'event_context'):
         context = self.menustack[-1].event_context
     rc.set_app_context(self, context)
Beispiel #2
0
 def set_event_context(self):
     """
     Set the event context
     """
     context = self.event_context
     if self.menustack and hasattr(self.menustack[-1], 'event_context'):
         context = self.menustack[-1].event_context
     rc.set_app_context(self, context)
Beispiel #3
0
 def reset_seek(self):
     logger.debug('seek timeout')
     self.seek = 0
     rc.set_app_context(self, 'video')
Beispiel #4
0
    def eventhandler(self, event, menuw=None):
        """
        eventhandler for mplayer control. If an event is not bound in this
        function it will be passed over to the items eventhandler
        """
        logger.debug('%s.eventhandler(event=%s)', self.__class__, event)
        if not self.app:
            return self.item.eventhandler(event)

        for p in self.plugins:
            if p.eventhandler(event):
                return True

        if event == VIDEO_MANUAL_SEEK:
            self.seek = 0
            rc.set_app_context(self, 'input')
            dialog.show_message("input")
            return True

        if event.context == 'input':
            if event in INPUT_ALL_NUMBERS:
                self.reset_seek_timeout()
                self.seek = self.seek * 10 + int(event);
                return True

            elif event == INPUT_ENTER:
                self.seek_timer.cancel()
                self.seek *= 60
                self.app.write('seek ' + str(self.seek) + ' 2\n')
                logger.debug("seek " + str(self.seek) + " 2\n")
                self.seek = 0
                rc.set_app_context(self, 'video')
                return True

            elif event == INPUT_EXIT:
                logger.debug('seek stopped')
                #self.app.write('seek stopped\n')
                self.seek_timer.cancel()
                self.seek = 0
                rc.set_app_context(self, 'video')
                return True

        if event == STOP:
            self.stop()
            return self.item.eventhandler(event)

        if event == 'AUDIO_ERROR_START_AGAIN':
            self.stop()
            self.play(self.options, self.item)
            return True

        if event in (PLAY_END, USER_END):
            self.stop()
            return self.item.eventhandler(event)

        if event == VIDEO_SEND_MPLAYER_CMD:
            self.app.write('%s\n' % event.arg)
            return True

        if event == TOGGLE_OSD:
            if dialog.is_dialog_supported():
                if self.play_state_dialog is None:
                    if self.paused:
                        self.play_state_dialog = dialog.show_play_state(dialog.PLAY_STATE_INFO, self.item, self.get_stored_time_info)
                    else:
                        self.play_state_dialog = dialog.show_play_state(dialog.PLAY_STATE_INFO, self.item, self.get_time_info)
                else:
                    self.play_state_dialog.hide()
                    self.play_state_dialog = None
            else:
                self.paused = False
                self.app.write('osd\n')
            return True

        if event == PAUSE or event == PLAY:
            self.paused = not self.paused
            # We have to store the current time before displaying the dialog
            # otherwise the act of requesting the current position resumes playback!
            if self.paused:
                self.stored_time_info = self.get_time_info()
                self.play_state_dialog = dialog.show_play_state(dialog.PLAY_STATE_PAUSE, self.item, self.get_stored_time_info)
                self.app.write('pause\n')
            else:
                self.app.write('speed_set 1.0\n')
                self.play_state_dialog = dialog.show_play_state(dialog.PLAY_STATE_PLAY, self.item, self.get_time_info)

            return True

        if event == SEEK:
            if event.arg > 0 and self.item_length != -1 and self.dynamic_seek_control:
                # check if the file is growing
                if self.item_info.get_endpos() == self.item_length:
                    # not growing, deactivate this
                    self.item_length = -1

                self.dynamic_seek_control = False

            if event.arg > 0 and self.item_length != -1:
                # safety time for bad mplayer seeking
                seek_safety_time = 20
                if self.item_info['type'] in ('MPEG-PES', 'MPEG-TS'):
                    seek_safety_time = 500

                # check if seek is allowed
                if self.item_length <= self.item.elapsed + event.arg + seek_safety_time:
                    # get new length
                    self.item_length = self.item_info.get_endpos()

                # check again if seek is allowed
                if self.item_length <= self.item.elapsed + event.arg + seek_safety_time:
                    logger.debug('unable to seek %s secs at time %s, length %s', event.arg, self.item.elapsed, self.item_length)
                    dialog.show_message(_('Seeking not possible'))
                    return False
            
            self.paused = False
            self.app.write('seek %s\n' % event.arg)
            if event.arg > 0:
                self.play_state_dialog = dialog.show_play_state(dialog.PLAY_STATE_SEEK_FORWARD, self.item, self.get_time_info)
            else:
                self.play_state_dialog = dialog.show_play_state(dialog.PLAY_STATE_SEEK_BACK, self.item, self.get_time_info)
            return True

        if event == VIDEO_AVSYNC:
            self.app.write('audio_delay %g\n' % float(event.arg));
            if config.MPLAYER_USE_OSD_SHOW_PROPS:
                self.app.write('osd_show_property_text "Audio delay ${audio_delay}" 2000\n')
            return True

        if event == VIDEO_SUBSYNC:
            self.app.write('sub_delay %g\n' % float(event.arg));
            if config.MPLAYER_USE_OSD_SHOW_PROPS:
                self.app.write('osd_show_property_text "Subtitles delay ${sub_delay}" 2000\n')
            return True

        if event == VIDEO_NEXT_AUDIOLANG:
            self.app.write('switch_audio\n')
            if config.MPLAYER_USE_OSD_SHOW_PROPS:
                self.app.write('osd_show_property_text "Audio ${switch_audio}" 2000\n')
            return True

        if event == VIDEO_NEXT_SUBTITLE:
            self.app.write('sub_select\n')
            if config.MPLAYER_USE_OSD_SHOW_PROPS:
                self.app.write('osd_show_property_text "Subtitles ${sub_file}" 2000\n')
            return True

        if event == OSD_MESSAGE:
            self.show_message(event.arg)
            return True

        if event == 'MPLAYER_VO':
            if config.OSD_SINGLE_WINDOW:
                w_ratio = float(config.CONF.width) / float(event.arg[0])
                h_ratio = float(config.CONF.height) / float(event.arg[1])
                ratio = min(w_ratio, h_ratio)
                w = int(event.arg[0] * ratio)
                h = int(event.arg[1] * ratio)
                x = (config.CONF.width - w) / 2
                y = (config.CONF.height - h) / 2
                osd.video_window.set_geometry((x,y), (w,h))
                osd.video_window.show()
            return True

        # nothing found? Try the eventhandler of the object who called us
        return self.item.eventhandler(event)
Beispiel #5
0
 def reset_seek(self):
     logger.debug('seek timeout')
     self.seek = 0
     rc.set_app_context(self, 'video')
Beispiel #6
0
    def eventhandler(self, event, menuw=None):
        """
        eventhandler for mplayer control. If an event is not bound in this
        function it will be passed over to the items eventhandler
        """
        logger.debug('%s.eventhandler(event=%s)', self.__class__, event)
        if not self.app:
            return self.item.eventhandler(event)

        for p in self.plugins:
            if p.eventhandler(event):
                return True

        if event == VIDEO_MANUAL_SEEK:
            self.seek = 0
            rc.set_app_context(self, 'input')
            dialog.show_message("input")
            return True

        if event.context == 'input':
            if event in INPUT_ALL_NUMBERS:
                self.reset_seek_timeout()
                self.seek = self.seek * 10 + int(event)
                return True

            elif event == INPUT_ENTER:
                self.seek_timer.cancel()
                self.seek *= 60
                self.app.write('seek ' + str(self.seek) + ' 2\n')
                logger.debug("seek " + str(self.seek) + " 2\n")
                self.seek = 0
                rc.set_app_context(self, 'video')
                return True

            elif event == INPUT_EXIT:
                logger.debug('seek stopped')
                #self.app.write('seek stopped\n')
                self.seek_timer.cancel()
                self.seek = 0
                rc.set_app_context(self, 'video')
                return True

        if event == STOP:
            self.stop()
            return self.item.eventhandler(event)

        if event == 'AUDIO_ERROR_START_AGAIN':
            self.stop()
            self.play(self.options, self.item)
            return True

        if event in (PLAY_END, USER_END):
            self.stop()
            return self.item.eventhandler(event)

        if event == VIDEO_SEND_MPLAYER_CMD:
            self.app.write('%s\n' % event.arg)
            return True

        if event == TOGGLE_OSD:
            if dialog.is_dialog_supported():
                if self.play_state_dialog is None:
                    if self.paused:
                        self.play_state_dialog = dialog.show_play_state(
                            dialog.PLAY_STATE_INFO, self.item,
                            self.get_stored_time_info)
                    else:
                        self.play_state_dialog = dialog.show_play_state(
                            dialog.PLAY_STATE_INFO, self.item,
                            self.get_time_info)
                else:
                    self.play_state_dialog.hide()
                    self.play_state_dialog = None
            else:
                self.paused = False
                self.app.write('osd\n')
            return True

        if event == PAUSE or event == PLAY:
            self.paused = not self.paused
            # We have to store the current time before displaying the dialog
            # otherwise the act of requesting the current position resumes playback!
            if self.paused:
                self.stored_time_info = self.get_time_info()
                self.play_state_dialog = dialog.show_play_state(
                    dialog.PLAY_STATE_PAUSE, self.item,
                    self.get_stored_time_info)
                self.app.write('pause\n')
            else:
                self.app.write('speed_set 1.0\n')
                self.play_state_dialog = dialog.show_play_state(
                    dialog.PLAY_STATE_PLAY, self.item, self.get_time_info)

            return True

        if event == SEEK:
            if event.arg > 0 and self.item_length != -1 and self.dynamic_seek_control:
                # check if the file is growing
                if self.item_info.get_endpos() == self.item_length:
                    # not growing, deactivate this
                    self.item_length = -1

                self.dynamic_seek_control = False

            if event.arg > 0 and self.item_length != -1:
                # safety time for bad mplayer seeking
                seek_safety_time = 20
                if self.item_info['type'] in ('MPEG-PES', 'MPEG-TS'):
                    seek_safety_time = 500

                # check if seek is allowed
                if self.item_length <= self.item.elapsed + event.arg + seek_safety_time:
                    # get new length
                    self.item_length = self.item_info.get_endpos()

                # check again if seek is allowed
                if self.item_length <= self.item.elapsed + event.arg + seek_safety_time:
                    logger.debug(
                        'unable to seek %s secs at time %s, length %s',
                        event.arg, self.item.elapsed, self.item_length)
                    dialog.show_message(_('Seeking not possible'))
                    return False

            self.paused = False
            self.app.write('seek %s\n' % event.arg)
            if event.arg > 0:
                self.play_state_dialog = dialog.show_play_state(
                    dialog.PLAY_STATE_SEEK_FORWARD, self.item,
                    self.get_time_info)
            else:
                self.play_state_dialog = dialog.show_play_state(
                    dialog.PLAY_STATE_SEEK_BACK, self.item, self.get_time_info)
            return True

        if event == VIDEO_AVSYNC:
            self.app.write('audio_delay %g\n' % float(event.arg))
            if config.MPLAYER_USE_OSD_SHOW_PROPS:
                self.app.write(
                    'osd_show_property_text "Audio delay ${audio_delay}" 2000\n'
                )
            return True

        if event == VIDEO_SUBSYNC:
            self.app.write('sub_delay %g\n' % float(event.arg))
            if config.MPLAYER_USE_OSD_SHOW_PROPS:
                self.app.write(
                    'osd_show_property_text "Subtitles delay ${sub_delay}" 2000\n'
                )
            return True

        if event == VIDEO_NEXT_AUDIOLANG:
            self.app.write('switch_audio\n')
            if config.MPLAYER_USE_OSD_SHOW_PROPS:
                self.app.write(
                    'osd_show_property_text "Audio ${switch_audio}" 2000\n')
            return True

        if event == VIDEO_NEXT_SUBTITLE:
            self.app.write('sub_select\n')
            if config.MPLAYER_USE_OSD_SHOW_PROPS:
                self.app.write(
                    'osd_show_property_text "Subtitles ${sub_file}" 2000\n')
            return True

        if event == OSD_MESSAGE:
            self.show_message(event.arg)
            return True

        if event == 'MPLAYER_VO':
            if config.OSD_SINGLE_WINDOW:
                w_ratio = float(config.CONF.width) / float(event.arg[0])
                h_ratio = float(config.CONF.height) / float(event.arg[1])
                ratio = min(w_ratio, h_ratio)
                w = int(event.arg[0] * ratio)
                h = int(event.arg[1] * ratio)
                x = (config.CONF.width - w) / 2
                y = (config.CONF.height - h) / 2
                osd.video_window.set_geometry((x, y), (w, h))
                osd.video_window.show()
            return True

        # nothing found? Try the eventhandler of the object who called us
        return self.item.eventhandler(event)