Pyglet does not play music in terminal (GStreamer-CRITICAL)

Viewed 85
import pyglet

source = pyglet.media.load("my_track.mp3")
source.play()

When I run this code in the terminal, an error appears:

((python3:10162): GStreamer-CRITICAL **: 14:26:38.754: Bus bus 1 has no signal watches attached

The code works correctly in the SublimeText3.

If I run wav instead of an mp3 file, then Sublime does fine again, but nothing happens in the terminal. There is no sound, no errors.

1 Answers

You need to add pyglet.app.run() at the end. The event loop is responsible for scheduling the sample decoding as well as keeping the program alive. Your example is just loading the source, trying to play it, then terminates the program before you can hear it.

Related