-1

I don't know how to get the name of the current source playing in pyglet, I put different sources in a playlist and the playlist is playing one of the sources randomly, here's my code:

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()

What I've tried:

print(player.source)

What I get:

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

And what i want is:

'filename.mp3'

I'm pretty bad with pyglet so please help me.

Thewhyap
  • 49
  • 10

1 Answers1

1

I'm not sure there is a way exactly built in, but if not seems easy to do yourself.

Is this not viable?

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

Then: print(player.source.filename)

Charlie
  • 680
  • 4
  • 11
  • Thanks but I just tried your code and i get: AttributeError: 'WMFSource' object has no attribute 'filename' so except if i'm doing something wrong this is not working... and if it was working I would have had a lot of trouble doing that for each file (I didn't say it in my post but I have more than 50 files in my code so I was searching something that is working automatically on all files) – Thewhyap May 10 '21 at 20:55
  • Strange, because `music1` should be the `WMFSource`, correct? It should have the attribute you set on it. Make sure you are *setting the filename attribute on all of the files*. Even if you have 50, you can solve this by using a list and iterating over it when loading the music. You will always have the filename at the point of loading the file, so you should always be able to set the attribute. – Charlie May 11 '21 at 03:55
  • Yes thanks a lot i did that and it's working now, and okay i'm gonna try that. – Thewhyap May 11 '21 at 08:23