7edd1592c5731c36d39dd6bdea5d2c1b4c9be97c
2 # This is a reworked version of the example from Jono Bacon's Python+Gstreamer primer:
3 # http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python/
5 # It uses Gstreamer 1.0, GTK3, and replaces alsa with pulse for audio output
6 # Info on porting python scripts to GStreamer 1.0 can be found here:
7 # https://wiki.ubuntu.com/Novacut/GStreamer1.0
10 gi
.require_version('Gtk', '3.0')
11 gi
.require_version('Gst', '1.0')
12 from gi
.repository
import Gtk
, Gst
18 # Create gui bits and bobs
20 self
.wTree
= Gtk
.Builder()
21 self
.wTree
.add_from_file("example2.glade")
24 "on_play_clicked" : self
.OnPlay
,
25 "on_stop_clicked" : self
.OnStop
,
26 "on_quit_clicked" : self
.OnQuit
,
29 self
.wTree
.connect_signals(signals
)
31 # Create GStreamer bits and bobs
33 # Initiate the pipeline
35 self
.pipeline
= Gst
.Pipeline()
37 # Add an audiotestsrc element to the pipeline
38 self
.audiotestsrc
= Gst
.ElementFactory
.make("audiotestsrc", "audio")
39 self
.audiotestsrc
.set_property("freq", 800)
40 self
.pipeline
.add(self
.audiotestsrc
)
42 # Add a pulsesink element to the pipeline
43 self
.pulsesink
= Gst
.ElementFactory
.make("pulsesink", "sink")
44 self
.pipeline
.add(self
.pulsesink
)
46 # Link the two elements together
47 self
.audiotestsrc
.link(self
.pulsesink
)
49 # Summon the window and connect the window's close button to Quit
50 self
.window
= self
.wTree
.get_object("mainwindow")
51 self
.window
.connect("delete-event", Gtk
.main_quit
)
52 self
.window
.show_all()
55 def OnPlay(self
, widget
):
57 self
.pipeline
.set_state(Gst
.State
.PLAYING
)
59 def OnStop(self
, widget
):
61 self
.pipeline
.set_state(Gst
.State
.READY
)
63 def OnQuit(self
, widget
):
67 # Workaround to get Ctrl+C to terminate from command line
68 # ref: https://bugzilla.gnome.org/show_bug.cgi?id=622084#c12
69 signal
.signal(signal
.SIGINT
, signal
.SIG_DFL
)