简体   繁体   English

Pyglet 不在终端中播放音乐 (GStreamer-CRITICAL)

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

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 ((python3:10162): GStreamer-CRITICAL **: 14:26:38.754: Bus bus 1 没有连接信号手表

The code works correctly in the SublimeText3.该代码在 SublimeText3 中正常工作。

If I run wav instead of an mp3 file, then Sublime does fine again, but nothing happens in the terminal.如果我运行 wav 而不是 mp3 文件,那么 Sublime 会再次正常运行,但终端中没有任何反应。 There is no sound, no errors.没有声音,没有错误。

You need to add pyglet.app.run() at the end.您需要在最后添加pyglet.app.run() 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.您的示例只是加载源,尝试播放它,然后在您听到它之前终止程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM