This wiki is in the process of being archived due to lack of usage and the resources necessary to serve it — predominately to bots, crawlers, and LLM companies. Edits are discouraged.
Pages are preserved as they were at the time of archival. For current information, please visit python.org.
If a change to this archive is absolutely needed, requests can be made via the infrastructure@python.org mailing list.

Using GStreamer with PyQt

This example code was posted to the PyQt mailing list in a message by Baz Walter.

   1 import sys, os
   2 import gobject, pygst
   3 pygst.require('0.10')
   4 import gst
   5 from PyQt4.QtCore import SIGNAL, SLOT
   6 from PyQt4.QtGui import QApplication, QMainWindow, QPushButton, \
   7                          QFileDialog
   8 
   9 
  10 class MainWindow(QMainWindow):
  11      def __init__(self):
  12          QMainWindow.__init__(self)
  13          self.setWindowTitle('Audio-Player')
  14          self.resize(120, 50)
  15          self.move(500, 500)
  16          self.button = QPushButton(self)
  17          self.button.setText('Start')
  18          self.button.setMinimumSize(90, 0)
  19          self.setCentralWidget(self.button)
  20          self.connect(self.button, SIGNAL('clicked()'), self.start_stop)
  21          self.player = gst.element_factory_make('playbin', 'player')
  22          try:
  23              # alsasink pulsesink osssink autoaudiosink
  24              device = gst.parse_launch('alsasink')
  25          except gobject.GError:
  26              print 'Error: could not launch audio sink'
  27          else:
  28              self.player.set_property('audio-sink', device)
  29              self.bus = self.player.get_bus()
  30              self.bus.add_signal_watch()