Python Pyglet 播放器 on_eos 装饰器未被调用
Python Pyglet player on_eos decorator not being called
我目前正在尝试让 python 媒体播放器在当前源结束后自动排队并播放随机源。为此,我一直在与玩家事件角力 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')
甚至定义了一个定义 on_eos 的播放器子类,所有这些都没有效果。这是 on_eos 从未被发送的错误,还是我遗漏了什么?
这应该适合你:
Player = pyglet.media.Player()
# our event handling function
def on_eos():
print("on player eos")
Player.push_handlers(on_eos)
我目前正在尝试让 python 媒体播放器在当前源结束后自动排队并播放随机源。为此,我一直在与玩家事件角力 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')
甚至定义了一个定义 on_eos 的播放器子类,所有这些都没有效果。这是 on_eos 从未被发送的错误,还是我遗漏了什么?
这应该适合你:
Player = pyglet.media.Player()
# our event handling function
def on_eos():
print("on player eos")
Player.push_handlers(on_eos)