gpt4 book ai didi

python - Pyglet,播放器,下一首歌

转载 作者:行者123 更新时间:2023-12-02 23:56:27 25 4
gpt4 key购买 nike

我正在尝试通过pyglet在Python 3中播放歌曲。我可以播放和停止播放一首歌曲,但是当我尝试播放下一首歌曲时会产生错误。 I followed these instructions.我将在tkinter中执行该程序。

我的代码:

import pyglet
import glob
from tkinter import Tk, Button
songs=glob.glob("*.mp3")
player=pyglet.media.Player()
def play_song():
global player
for i in range(len(songs)):
source=pyglet.resource.media(songs[i])
player.queue(source)
player.play()
def pause_song():
player.pause()
def next_song():
player.next()

window=Tk()
play_=Button(text="play", command=play_song)
play_.pack()
pause_=Button(text="pause", command=pause_song)
pause_.pack()
next_=Button(text="next", command=next_song)
next_.pack()
window.mainloop()

错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1442, in __call__
return self.func(*args)
File "C:\Documents and Settings\Fany\Dokumenty\Hudba\Sabaton\2012 - Carolus Rex\py.py", line 15, in next_song
player.next()
AttributeError: 'Player' object has no attribute 'next'

最佳答案

尝试对您的next_song()进行以下更改

def next_song():
player.next_source()

原因
引用此页
https://pyglet.readthedocs.org/en/pyglet-1.2-maintenance/api/pyglet/media/pyglet.media.Player.html#pyglet.media.Player.time

您会发现next()已“弃用”,建议使用next_source()而不是

高温超导

PS 当我在您的计算机上测试了您的代码片段时,它可以正常工作。

关于python - Pyglet,播放器,下一首歌,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15380488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com