Minimalist examples of audio players in python, using the new Gstreamer 1.0 API

hadware hadware Last update: Mar 27, 2022

gstreamer-python-player

Various examples of minimalist music players in python, using the new Gstreamer 1.0 API.The point is to cover by example the following implementations using Gstreamer 1.0 and the GTK+3 API:

  • Pipeline usage
  • Use a full "read -> decode -> output to sink" pipeline
  • Simply play an audio file using gstreamer and python
  • Use a slider to display the stream's current playback position, and change it

player.py

A simple python conversion of the following bash gstreamer command:

    gst-launch-1.0 filesrc location="/path/to/your/file.mp3" ! decodebin ! alsasink

It doesn't contain any graphical elements (no Gtk window or else). There is a small catch here: the decodebin doesn't have a source pad before startup, thus, we cannot connect it to the sink before it's been fed with a stream. We have to wait for it to create its output pad, signal it, and then handler the signal event to connect the pad to the sink's pad

player_minimal.py

Instead of a "full" pipeline, here it's just an example of some adapted code from this page.

It uses the "playbin" element which condenses all the elements from the player.py example into one automagic element.

seek.py

Mainly a gst1.0 port and simplification of this code.

The simplest possible example of a sound player: a "Play" button, a "Pause" button, and a slider to control the playback position. It makes usage of controls signals to start at stop the element's playback state, and uses a Glib timer to check on the current position of the stream. When the slider is manually moved, it also makes use of the seek_simple() function to seek in the stream.

You should probably use the official doc as well as the gstreamer1.0 porting tutorial to start using the gstreamer1.0 API while feeding on gst0.10-based examples.

Subscribe to our newsletter