我正在尝试通过 pyglet 在 Python 3 中播放歌曲。我可以播放和停止一首歌曲,但是当我尝试播放下一首歌曲时,它会产生错误。我按照这些说明进行操作。我将在 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'