Added alt. glade file, changed frequency, use alt. glade file
[python-gstreamer-examples] / example2.py
1 #!/usr/bin/env python
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/
4 #
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
8
9 from gi.repository import Gtk, Gst
10 import signal
11
12 class Main:
13 def __init__(self):
14
15 # Create gui bits and bobs
16
17 self.wTree = Gtk.Builder()
18 self.wTree.add_from_file("example2_2.glade")
19
20 signals = {
21 "on_play_clicked" : self.OnPlay,
22 "on_stop_clicked" : self.OnStop,
23 "on_quit_clicked" : self.OnQuit,
24 }
25
26 self.wTree.connect_signals(signals)
27
28 # Create GStreamer bits and bobs
29
30 # Initiate the pipeline
31 Gst.init(None)
32 self.pipeline = Gst.Pipeline("mypipeline")
33
34 # Add an audiotestsrc element to the pipeline
35 self.audiotestsrc = Gst.ElementFactory.make("audiotestsrc", "audio")
36 self.audiotestsrc.set_property("freq", 800)
37 self.pipeline.add(self.audiotestsrc)
38
39 # Add a pulsesink element to the pipeline
40 self.pulsesink = Gst.ElementFactory.make("pulsesink", "sink")
41 self.pipeline.add(self.pulsesink)
42
43 # Link the two elements together
44 self.audiotestsrc.link(self.pulsesink)
45
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()
50
51
52 def OnPlay(self, widget):
53 print "play"
54 self.pipeline.set_state(Gst.State.PLAYING)
55
56 def OnStop(self, widget):
57 print "stop"
58 self.pipeline.set_state(Gst.State.READY)
59
60 def OnQuit(self, widget):
61 print "quit"
62 Gtk.main_quit()
63
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)
67
68 start = Main()
69 Gtk.main()