我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用gi.repository.Gst()。
def on_close(self, widget, data=None): """ Close and dispose everything that needs to be when window is closed. """ # Stop timers if self.play_status_updater is not None: self.play_status_updater.stop() if self.sleep_timer is not None: self.sleep_timer.stop() # save current position when still playing if player.get_gst_player_state() == Gst.State.PLAYING: db.Track.update(position=player.get_current_duration()).where( db.Track.id == player.get_current_track().id).execute() player.stop() player.dispose() #################### # CONTENT HANDLING # ####################
def on_message(self, bus, message): # Getting the RMS audio level value: s = Gst.Message.get_structure(message) if message.type == Gst.MessageType.ELEMENT: if str(Gst.Structure.get_name(s)) == "level": percentage = self.iec_scale(s.get_value("rms")[0]) # This is not a true stereo signal. self.vumeter_left.set_fraction(percentage) self.vumeter_right.set_fraction(percentage) t = message.type if t == Gst.MessageType.EOS: self.streampipe.set_state(Gst.State.NULL) elif t == Gst.MessageType.ERROR: err, debug = message.parse_error() print ('%s' % err, debug) # DEBUG # Watching for feed loss during streaming: #if '(651)' not in debug: # # The error is not a socket error. # self.pipel.stream_stop() # self.build_filename(streamfailed=True) # self.create_backup_pipeline()
def start(self): if not hasattr(self.pipeline, 'pipeline'): logger.error('Pipeline could not be parsed, exiting') self.exit() audio_fakesink = self.pipeline.pipeline.get_by_name("afakesink") self._audio_fakesink_pad = audio_fakesink.get_static_pad('sink') self._id_prob_audio_sink = self._audio_fakesink_pad.add_probe(Gst.PadProbeType.BUFFER, self.on_audio_fakesink_buffer, None) video_fakesink = self.pipeline.pipeline.get_by_name("vfakesink") self._video_src_pad = video_fakesink.get_static_pad('sink') self._id_prob_video_sink = self._video_src_pad.add_probe(Gst.PadProbeType.BUFFER, self.on_video_fakesink_buffer, None) self.pipeline_success = False self.pipeline.run() self._start_time = time.time() logger.info("start pipeline")
def stv_mv_play(self, *args): if Gst.State.PLAYING == app.player.state: app.player.pause() app.bt_play.set_image(app.pause_img) elif Gst.State.PAUSED == app.player.state: app.player.play() app.bt_play.set_image(app.play_img) elif Gst.State.NULL == app.player.state: ok = app.play_list_play() if ok: app.bt_play.set_image(app.play_img)
def play_list_stop(self): if Gst.State.NULL != self.player.state: self.player.stop() self.bt_play.set_image(self.pause_img)
def __timer_switch_changed(self, sender, widget): """ Start/Stop the sleep timer object. """ if self.timer_switch.get_active(): self.timer_image.set_from_icon_name( "timer-on-symbolic", Gtk.IconSize.BUTTON) if player.get_gst_player_state() == Gst.State.PLAYING: self.__start_sleep_timer() else: self.timer_image.set_from_icon_name( "timer-off-symbolic", Gtk.IconSize.BUTTON) if self.sleep_timer is not None: self.sleep_timer.stop()
def __sleep_timer_fired(self): """ The sleep timer gets called every second. Here we do the countdown stuff aswell as stop the playback / suspend the machine. """ self.current_timer_time = self.current_timer_time - 1 adjustment = self.timer_spinner.get_adjustment() adjustment.set_value(int(self.current_timer_time / 60) + 1) if self.current_timer_time < 1: self.timer_switch.set_active(False) if player.get_gst_player_state() == Gst.State.PLAYING: player.play_pause(None) self.sleep_timer.stop()