Beispiel #1
0
    def set_value(self, val, all_vals=None, doupdate=True):
        if self.property_type == 'bitrate':
            try:
                val = str(float(val) / 1000.0) + ' kbps'
            except (TypeError, ValueError):
                pass
        elif self.property_type == 'timestamp':
            d = datetime.datetime.fromtimestamp(val)
            val = d.strftime("%x %X")
        elif self.property_type == 'time':
            val = "%(m)d:%(s)02d" % {'m': val // 60, 's': val % 60}
        elif self.property_type == 'location':
            f = Gio.File.new_for_uri(val)
            val = f.get_parse_name()

            if not f.get_path():
                # Sanitize URLs of remote locations
                val = common.sanitize_url(val)
                # Disable folder button for non-browsable locations
                self.folder_button.set_sensitive(False)
        else:
            val = str(val)

        if doupdate:
            self.field.set_text(val)
            self.field.set_tooltip_text(val)
Beispiel #2
0
    def set_value(self, val, all_vals=None, doupdate=True):
        if self.property_type == 'bitrate':
            try:
                val = str(float(val) / 1000.0) + ' kbps'
            except (TypeError, ValueError):
                pass
        elif self.property_type == 'timestamp':
            d = datetime.datetime.fromtimestamp(val)
            val = d.strftime("%x %X")
        elif self.property_type == 'time':
            val = "%(m)d:%(s)02d" % {'m': val // 60, 's': val % 60}
        elif self.property_type == 'location':
            f = Gio.File.new_for_uri(val)
            val = f.get_parse_name()

            if not f.get_path():
                # Sanitize URLs of remote locations
                val = common.sanitize_url(val)
                # Disable folder button for non-browsable locations
                self.folder_button.set_sensitive(False)
        else:
            val = str(val)

        if doupdate:
            self.field.set_text(val)
            self.field.set_tooltip_text(val)
Beispiel #3
0
    def play(
        self,
        track,
        start_at,
        paused,
        already_queued,
        fade_in_duration=None,
        fade_out_duration=None,
    ):
        '''fade duration is in seconds'''

        if not already_queued:
            self.stop(emit_eos=False)

            # For the moment, the only safe time to add/remove elements
            # is when the playbin is NULL, so do that here..
            if self.audio_filters.setup_elements():
                self.logger.debug("Applying audio filters")
                self.playbin.props.audio_filter = self.audio_filters
            else:
                self.logger.debug("Not applying audio filters")
                self.playbin.props.audio_filter = None

        if self.needs_sink:
            self.reconfigure_sink()

        self.current_track = track
        self.last_position = 0
        self.buffered_track = None

        uri = track.get_loc_for_io()
        self.logger.info("Playing %s", common.sanitize_url(uri))

        # This is only set for gapless playback
        if not already_queued:
            self.playbin.set_property("uri", uri)
            if urlparse.urlsplit(uri)[0] == "cdda":
                self.notify_id = self.playbin.connect('source-setup',
                                                      self.on_source_setup,
                                                      track)

        # Start in paused mode if we need to seek
        if paused or start_at is not None:
            self.playbin.set_state(Gst.State.PAUSED)
        elif not already_queued:
            self.playbin.set_state(Gst.State.PLAYING)

        self.fader.setup_track(track,
                               fade_in_duration,
                               fade_out_duration,
                               now=0)

        if start_at is not None:
            self.seek(start_at)
            if not paused:
                self.playbin.set_state(Gst.State.PLAYING)

        if paused:
            self.fader.pause()
Beispiel #4
0
    def play(
        self,
        track,
        start_at,
        paused,
        already_queued,
        fade_in_duration=None,
        fade_out_duration=None,
    ):
        '''fade duration is in seconds'''

        if not already_queued:
            self.stop(emit_eos=False)

            # For the moment, the only safe time to add/remove elements
            # is when the playbin is NULL, so do that here..
            if self.audio_filters.setup_elements():
                self.logger.debug("Applying audio filters")
                self.playbin.props.audio_filter = self.audio_filters
            else:
                self.logger.debug("Not applying audio filters")
                self.playbin.props.audio_filter = None

        if self.needs_sink:
            self.reconfigure_sink()

        self.current_track = track
        self.last_position = 0
        self.buffered_track = None

        uri = track.get_loc_for_io()
        self.logger.info("Playing %s", common.sanitize_url(uri))

        # This is only set for gapless playback
        if not already_queued:
            self.playbin.set_property("uri", uri)
            if urlparse.urlsplit(uri)[0] == "cdda":
                self.notify_id = self.playbin.connect(
                    'source-setup', self.on_source_setup, track
                )

        # Start in paused mode if we need to seek
        if paused or start_at is not None:
            self.playbin.set_state(Gst.State.PAUSED)
        elif not already_queued:
            self.playbin.set_state(Gst.State.PLAYING)

        self.fader.setup_track(track, fade_in_duration, fade_out_duration, now=0)

        if start_at is not None:
            self.seek(start_at)
            if not paused:
                self.playbin.set_state(Gst.State.PLAYING)

        if paused:
            self.fader.pause()
Beispiel #5
0
    def format(self, track, parameters):
        """
            Formats a raw tag value

            :param track: the track to get the tag from
            :type track: :class:`xl.trax.Track`
            :param parameters: optionally passed parameters
            :type parameters: dictionary
            :returns: the formatted value
            :rtype: string
        """
        path = track.get_local_path()
        if path is not None:
            return path
        return common.sanitize_url(track.get_tag_raw('__loc'))
Beispiel #6
0
    def format(self, track, parameters):
        """
            Formats a raw tag value

            :param track: the track to get the tag from
            :type track: :class:`xl.trax.Track`
            :param parameters: optionally passed parameters
            :type parameters: dictionary
            :returns: the formatted value
            :rtype: string
        """
        path = track.get_local_path()
        if path is not None:
            return path
        return common.sanitize_url(track.get_tag_raw('__loc'))
Beispiel #7
0
 def on_about_to_finish(self, *args):
     '''
         This function exists solely to allow gapless playback for audio
         formats that support it. Setting the URI property of the playbin
         will queue the track for playback immediately after the previous 
         track.
         
         .. note:: This is called from the gstreamer thread
     '''
     
     if self.engine.crossfade_enabled:
         return
     
     track = self.engine.player.engine_autoadvance_get_next_track(gapless=True)
     if track:
         uri = track.get_loc_for_io()
         self.playbin.set_property('uri', uri)
         self.buffered_track = track
         
         self.logger.debug("Gapless transition: queuing %s", common.sanitize_url(uri))
Beispiel #8
0
 def on_about_to_finish(self, *args):
     '''
         This function exists solely to allow gapless playback for audio
         formats that support it. Setting the URI property of the playbin
         will queue the track for playback immediately after the previous 
         track.
         
         .. note:: This is called from the gstreamer thread
     '''
     
     if self.engine.crossfade_enabled:
         return
     
     track = self.engine.player.engine_autoadvance_get_next_track(gapless=True)
     if track:
         uri = track.get_loc_for_io()
         self.playbin.set_property('uri', uri)
         self.buffered_track = track
         
         self.logger.debug("Gapless transition: queuing %s", common.sanitize_url(uri))
Beispiel #9
0
    def _next_track(self, track, already_playing=False):
        """
            internal api: advances the track to the next track
        """
        if track is None:
            self.stop()
            return False
        elif not already_playing:
            self.stop(_fire=False)
        else:
            self.stop(_fire=False, _onlyfire=True)

        playing = self.is_playing()

        if not playing:
            event.log_event('playback_reconfigure_bins', self, None)

        self._current = track

        uri = track.get_loc_for_io()
        logger.info("Playing %s" % common.sanitize_url(uri))
        self._reset_playtime_stamp()
        
        if not already_playing:
            self._pipe.set_property("uri", uri)
            if urlparse.urlsplit(uri)[0] == "cdda":
                self.notify_id = self._pipe.connect('notify::source',
                        self.__notify_source)
            
            self._pipe.set_state(gst.STATE_PLAYING)
        
        if not playing:
            event.log_event('playback_player_start', self, track)
        event.log_event('playback_track_start', self, track)
        
        if playing and self._should_delay_start():
            self._last_position = 0
        
        self._setup_startstop_offsets(track)
        
        return True
Beispiel #10
0
    def _next_track(self, track, already_playing=False):
        """
            internal api: advances the track to the next track
        """
        if track is None:
            self.stop()
            return False
        elif not already_playing:
            self.stop(_fire=False)
        else:
            self.stop(_fire=False, _onlyfire=True)

        playing = self.is_playing()

        if not playing:
            event.log_event('playback_reconfigure_bins', self, None)

        self._current = track

        uri = track.get_loc_for_io()
        logger.info("Playing %s" % common.sanitize_url(uri))
        self._reset_playtime_stamp()

        if not already_playing:
            self._pipe.set_property("uri", uri)
            if urlparse.urlsplit(uri)[0] == "cdda":
                self.notify_id = self._pipe.connect('notify::source',
                                                    self.__notify_source)

            self._pipe.set_state(gst.STATE_PLAYING)

        if not playing:
            event.log_event('playback_player_start', self, track)
        event.log_event('playback_track_start', self, track)

        if playing and self._should_delay_start():
            self._last_position = 0

        self._setup_startstop_offsets(track)

        return True