コード例 #1
0
ファイル: audio.py プロジェクト: Naelitz/soundclip
    def __init__(self, source, target_volume=1.0, postpone_duration_discovery=False, **properties):
        super().__init__(**properties)

        logger.debug("Initializing to source {0}".format(source))
        self.__source = source

        self.__fading = False
        self.__fade_func = fade_curve_linear
        self.__fade_func_args = {}
        self.__fade_start_time = 0
        self.__fade_duration = 0
        self.__fade_start_vol = 0
        self.__fade_target_volume = max(min(target_volume, 10.0), 0.0)
        self.__fade_complete_func = None

        self.__pipeline = Gst.Pipeline()

        self.__bus = self.__pipeline.get_bus()
        self.__bus.add_signal_watch()
        self.__bus.connect('message::eos', self.on_eos)
        self.__bus.connect('message::error', self.on_error)

        self.__dec = Gst.ElementFactory.make('uridecodebin', None)
        self.__dec.set_property('uri', self.__source)
        self.__dec.connect('pad-added', self.__on_decoded_pad)
        self.__dec.connect('drained', lambda *x: GLib.idle_add(self.on_drained))
        self.__conv = Gst.ElementFactory.make('audioconvert', None)
        self.__conv_sink = self.__conv.get_static_pad('sink')
        self.__rgvol = Gst.ElementFactory.make('rgvolume', None)
        self.__vol = Gst.ElementFactory.make('volume', None)
        self.__sink = Gst.ElementFactory.make('autoaudiosink', None)

        self.__pipeline.add(self.__dec)
        self.__pipeline.add(self.__conv)
        self.__pipeline.add(self.__rgvol)
        self.__pipeline.add(self.__vol)
        self.__pipeline.add(self.__sink)

        self.__conv.link(self.__rgvol)
        self.__rgvol.link(self.__vol)
        self.__vol.link(self.__sink)

        if PlaybackController.async_discoverer is None:
            PlaybackController.__setup_discoverer()

        if not postpone_duration_discovery:
            dur = int(PlaybackController.discoverer.discover_uri(source).get_duration() / Gst.MSECOND)
            logger.debug("Discovered length {0}".format(util.timefmt(dur)))
            self.__duration = dur
        else:
            logger.debug("Postponing duration discovery")
            self.__did = PlaybackController.async_discoverer.connect('discovered', self.__discoverer_async_callback)
            PlaybackController.async_discoverer.discover_uri_async(source)
            self.__duration = 0

        # Schedule a tick on 50ms interval
        self.__active = True
        GLib.timeout_add(50, self.tick)
        self.__last_update_time = 0
コード例 #2
0
ファイル: audio.py プロジェクト: Naelitz/soundclip
 def __discoverer_async_callback(self, discoverer, info, error):
     if info.get_uri() == self.__source:
         if error:
             logger.error("Error during discovery: {0}".format(error))
         else:
             dur = int(info.get_duration() / Gst.MSECOND)
             logger.debug("Discovered length {0} for {1}".format(util.timefmt(dur), self.__source))
             self.__duration = dur
             self.emit('duration-discovered', dur)
コード例 #3
0
ファイル: cuelist.py プロジェクト: Naelitz/soundclip
 def __get_elapsed_post_text(cue):
     return util.timefmt(cue.elapsed_postwait if cue.state is not PlaybackState.STOPPED else cue.post_wait)
コード例 #4
0
ファイル: cuelist.py プロジェクト: Naelitz/soundclip
 def __get_elapsed_text(cue):
     return util.timefmt(cue.elapsed if cue.state is not PlaybackState.STOPPED else cue.duration)