我的播放机中有多首歌曲正在加载和排队,但是播放机在第一首歌曲之后停止,我必须使用next_source()手动强制下一首歌曲,尽管从文档中我认为这应该是自动的。你知道吗
我运行的是python3.7.1和pyglet1.3.2,我浏览了文档并尝试了不同的数据排队方法。我已经研究了确保文件完全播放,虽然我不确定是否播放结束的第一首歌。你知道吗
chosenDirectory = ""
cSong = ""
cSongIndex = 0
player = pyglet.media.Player()
songList = []
def chooseDirectory():
global chosenDirectory
chosenDirectory = tk.filedialog.askdirectory(initialdir="/")
lbl.configure(text=chosenDirectory)
listBox.delete("0", "end")
def listFiles(dir):
global songList
songList = []
files = os.listdir(dir)
for x, file in enumerate(files):
filePath = chosenDirectory + "/" + file
if not os.path.isdir(filePath):
fileExt = file.split(".")[1]
if fileExt == "mp3" or fileExt == "wav":
listBox.insert(x, file)
songList.append(filePath)
listFiles(chosenDirectory)
class mediaControls:
def curSelect(self, info):
global cSong
if listBox.curselection() != ():
selected = listBox.get(listBox.curselection())
if selected != cSong:
cSong = selected
cSongIndex = listBox.curselection()[0]
self.playList()
def playSong(self):
if not player.playing:
player.play()
elif player.playing:
player.pause()
def playList(self):
for song in songList:
music = pyglet.media.load(song)
print(music.duration)
player.queue(music)
self.playSong()
def playNextSong(self):
player.next_source()
def playNewSong(self):
global cSong
global cSongIndex
cSongIndex = cSongIndex + 1
cSong = listBox.get(cSongIndex)
self.playSong()
我的预期结果是,在进入下一首歌之前,它会循环播放所有歌曲,而不需要我的干预。你知道吗
所以我希望队列能够处理所有的事情,而没有意识到pyglet.app.run程序()命令实际上是将所有事件设置为运动的命令。如果不使用它(因为它是阻塞的),我就可以在\u eos()上继续调用下一个\u source()函数并得到相同的结果。你知道吗
我想谈谈
global
的使用,因为你似乎已经处理了它不能继续发挥的问题。通过使状态成为类的一部分,可以消除global的所有用法。当应用程序运行时,它会生成该类的一个实例,该实例在程序运行的整个期间都有效。考虑以下几点。你知道吗它不工作,因为你没有包括整个脚本。
listBox
似乎丢失了,并且应该是实例成员。你知道吗相关问题 更多 >
编程相关推荐