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
9 from gi
.repository
import Gtk
, Gst
15 # Create gui bits and bobs
17 self
.wTree
= Gtk
.Builder()
18 self
.wTree
.add_from_file("example2.glade")
21 "on_play_clicked" : self
.OnPlay
,
22 "on_stop_clicked" : self
.OnStop
,
23 "on_quit_clicked" : self
.OnQuit
,
26 self
.wTree
.connect_signals(signals
)
28 # Create GStreamer bits and bobs
30 # Initiate the pipeline
32 self
.pipeline
= Gst
.Pipeline("mypipeline")
34 # Add an audiotestsrc element to the pipeline
35 self
.audiotestsrc
= Gst
.ElementFactory
.make("audiotestsrc", "audio")
36 self
.audiotestsrc
.set_property("freq", 200)
37 self
.pipeline
.add(self
.audiotestsrc
)
39 # Add a pulsesink element to the pipeline
40 self
.pulsesink
= Gst
.ElementFactory
.make("pulsesink", "sink")
41 self
.pipeline
.add(self
.pulsesink
)
43 # Link the two elements together
44 self
.audiotestsrc
.link(self
.pulsesink
)
46 # Summon the window and connect the window's close button to Quit
47 self
.window
= self
.wTree
.get_object("mainwindow")
48 self
.window
.connect("delete-event", Gtk
.main_quit
)
49 self
.window
.show_all()
52 def OnPlay(self
, widget
):
54 self
.pipeline
.set_state(Gst
.State
.PLAYING
)
56 def OnStop(self
, widget
):
58 self
.pipeline
.set_state(Gst
.State
.READY
)
60 def OnQuit(self
, widget
):
64 # Workaround to get Ctrl+C to terminate from command line
65 # ref: https://bugzilla.gnome.org/show_bug.cgi?id=622084#c12
66 signal
.signal(signal
.SIGINT
, signal
.SIG_DFL
)