如何获取当前在 pyglet 中播放的源的名称?

How can I get the name of the current source playing in pyglet?

我不知道如何获取在 pyglet 中播放的当前源的名称,我将不同的源放在一个播放列表中,播放列表随机播放其中一个源,这是我的代码:

player = pyglet.media.Player()

music1 = pyglet.media.load('A file.mp3')
music2 = pyglet.media.load('An other file.mp3')
music = random.sample([music1, music2], k=2)

player.queue(music)
player.play()

我尝试过的:

print(player.source)

我得到的:

<pyglet.media.codecs.wmf.WMFSource object at 0x000002AE2C4CB610>

而我想要的是:

'filename.mp3'

我对 pyglet 很不了解所以请帮助我。

我不确定是否有完全内置的方法,但如果没有,您自己似乎很容易做到。

这不可行吗?

my_filename = 'A file.mp3'
music1 = pyglet.media.load(my_filename)
music1.filename = my_filename

然后: print(player.source.filename)