0
我目前正試圖讓一個python媒體播放器在當前源結束後自動排隊並播放一個隨機源。爲此,我一直在與球員事件摔跤on_eosPython pyglet播放器on_eos修飾器不被稱爲
import pyglet
import random
import os
#Global Variable Declarations
MusicDir = ""
MusicList = ""
CurrentIndex = 0
MaxSongs = 0
Player = pyglet.media.Player()
Player.eos_action = pyglet.media.Player.EOS_NEXT
@Player.event
def on_eos():
randomSong()
def getMusicDir():
global MusicDir
global MusicList
global MaxSongs
MusicDir = os.path.abspath("C:\music")
MusicList = os.listdir(MusicDir)
MaxSongs = len(MusicList)
def randomSong():
global CurrentIndex
global MusicList
global Player
CurrentIndex = random.randint(0, MaxSongs-1)
Player.queue(pyglet.media.load(MusicDir + "/" + MusicList[CurrentIndex]))
Player.next()
Player.play()
getMusicDir()
CurrentIndex = random.randint(0, MaxSongs-1)
Player.queue(pyglet.media.load(MusicDir + "/" + MusicList[CurrentIndex]))
Player.play()
然而on_eos()事件不會被調用。我已經通過了pyglet文件看,並試圖
@Player.event('on_eos')
,甚至定義播放器的sublcass定義on_eos,都沒有任何效果。這是一個錯誤,on_eos永遠不會被調度,或者我錯過了什麼?