Exemplo n.º 1
0
    def play(self, track, stop_last=True):
        """
            plays the specified track, overriding any currently playing track

            if the track cannot be played, playback stops completely
        """
        if track is None:
            self.stop()
            return False
        elif stop_last:
            self.stop(fire=False)
        else:
            self.stop(fire=False, onlyfire=True)

        playing = self.is_playing()

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

        self._current = track

        uri = track.get_loc_for_io()
        logger.info("Playing %s" % uri)
        self.reset_playtime_stamp()

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

        self.playbin.set_state(gst.STATE_PLAYING)
        if not playing:
            event.log_event('playback_player_start', self, track)
        event.log_event('playback_track_start', self, track)

        return True
Exemplo n.º 2
0
    def play(self, track, user=True):
        if not track:
            return  # we cant play nothing

        playing = self.is_playing()

        logger.debug("Attmepting to play \"%s\"" % track)
        next = 1 - self._current_stream

        if self.streams[next]:
            self.unlink_stream(self.streams[next])

        fading = False
        duration = 0

        if user:
            if settings.get_option("player/user_fade_enabled", False):
                fading = True
                duration = settings.get_option("player/user_fade", 1000)
            else:
                self.unlink_stream(self.streams[self._current_stream])
        else:
            if settings.get_option("player/crossfading", False):
                fading = True
                duration = settings.get_option("player/crossfade_duration",
                                               3000)
            else:
                self.unlink_stream(self.streams[self._current_stream])

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

        self.streams[next] = AudioStream("Stream%s" % (next), caps=self.caps)
        self.streams[next].dec.connect("drained", self._on_drained,
                                       self.streams[next])

        if not self.link_stream(self.streams[next], track):
            return False

        if fading:
            self.streams[next].set_volume(0)

        self.pipe.set_state(gst.STATE_PLAYING)
        self.streams[next]._settle_flag = 1
        glib.idle_add(self.streams[next].set_state, gst.STATE_PLAYING)
        glib.idle_add(self._set_state, self.pipe, gst.STATE_PLAYING)

        if fading:
            timeout = int(float(duration) / float(100))
            if self.streams[next]:
                glib.timeout_add(timeout, self._fade_stream,
                                 self.streams[next], 1)
            if self.streams[self._current_stream]:
                glib.timeout_add(timeout, self._fade_stream,
                                 self.streams[self._current_stream], -1, True)
            if settings.get_option("player/crossfading", False):
                time = int(track.get_tag_raw("__length") * 1000 - duration)
                glib.timer_id = glib.timeout_add(time, self._start_crossfade)

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

        return True
Exemplo n.º 3
0
    def play(self, track, user=True):
        if not track:
            return  # we cant play nothing

        playing = self.is_playing()

        logger.debug('Attmepting to play "%s"' % track)
        next = 1 - self._current_stream

        if self.streams[next]:
            self.unlink_stream(self.streams[next])

        fading = False
        duration = 0

        if user:
            if settings.get_option("player/user_fade_enabled", False):
                fading = True
                duration = settings.get_option("player/user_fade", 1000)
            else:
                self.unlink_stream(self.streams[self._current_stream])
        else:
            if settings.get_option("player/crossfading", False):
                fading = True
                duration = settings.get_option("player/crossfade_duration", 3000)
            else:
                self.unlink_stream(self.streams[self._current_stream])

        if not playing:
            event.log_event_sync("playback_reconfigure_bins", self, None)

        self.streams[next] = AudioStream("Stream%s" % (next), caps=self.caps)
        self.streams[next].dec.connect("drained", self._on_drained, self.streams[next])

        if not self.link_stream(self.streams[next], track):
            return False

        if fading:
            self.streams[next].set_volume(0)

        self.pipe.set_state(gst.STATE_PLAYING)
        self.streams[next]._settle_flag = 1
        glib.idle_add(self.streams[next].set_state, gst.STATE_PLAYING)
        glib.idle_add(self._set_state, self.pipe, gst.STATE_PLAYING)

        if fading:
            timeout = int(float(duration) / float(100))
            if self.streams[next]:
                glib.timeout_add(timeout, self._fade_stream, self.streams[next], 1)
            if self.streams[self._current_stream]:
                glib.timeout_add(timeout, self._fade_stream, self.streams[self._current_stream], -1, True)
            if settings.get_option("player/crossfading", False):
                time = int(track.get_tag_raw("__length") * 1000 - duration)
                glib.timer_id = glib.timeout_add(time, self._start_crossfade)

        self._current_stream = next
        if not playing:
            event.log_event("playback_player_start", self, track)
        event.log_event("playback_track_start", self, track)

        return True