我试图用Pyglet播放一首歌,但遇到了这个错误
NotImplementedError:视频还不支持静态源。你知道吗
但是文件是mp3格式的。我已经安装了AVbin11-win64.exe(avbin64.dll),它被复制到“C:\Windows\SysWOW64”文件夹中,从https://github.com/AVbin/AVbin/downloads下载。你知道吗
以下是我使用的脚本:
import pyglet
player = pyglet.media.Player()
source = pyglet.media.load(r'C:\Users\MANDAV\Desktop\New folder (2)\Diamond-
Platnumz-All-The-Way-Up-v2.mp3', streaming=False)
player.play()
player.app.run()
您的代码包含一些问题。
第一个是
player.app.run()
,player没有.app
—您可能正在寻找pyglet.app.run()
。你知道吗第二件事是你试图调用
player.play()
,但是你从来没有调用过player.queue(source)
。所以要么做source.play()
要么做player.queue(source)
(两者的作用完全相同,直接播放源代码将在后台创建一个播放器)第三件事是
streaming=False
。avbin(至少10个)在将mp3解码为静态源时遇到问题。不太清楚为什么,但是这个项目已经死了将近一个世纪(是的,在短短的几年里,这个代码已经死了10年)。你知道吗下面是一个最小的工作示例:
不过,你可能需要一些更多的功能,同时发挥你的东西。下面是一个更大的示例,说明如何为音乐播放应用程序创建一个起点:
如果您只是对播放声音感兴趣。
我衷心推荐Pydub。你知道吗
它不仅使用了libav,这在编码和解码时更像是一个实际的标准,而且还具有丰富的特性。例如将
.mp3
转换成.wav
,您可以控制音频增益,同时播放两个音源等相关问题 更多 >
编程相关推荐