First I’m going to explain what I’m trying to do and then explain my problem.
Okay so I’ve been making prototypes on a project that I hope to be working on over the summer. The project is a small media player and one of the requirements is to display the albulm artwork of an mp3 file.
After some research I found this library:
http://code.google.com/p/mutagen/
The reason I chose this library was because it doesn’t have any dependencies and it would make my application more portable.
After fidilling around with the code I was able to retrieve data from the mp3 file, such as the artist and recording year etc. I’ll give a little demonstration here:
from mutagen.mp3 import MP3
audio = MP3("born.mp3")
artist = audio["TPE1"]
print artist
In case this doesn’t make much sense, this is the tutorial that is provided by mutagen – http://code.google.com/p/mutagen/wiki/Tutorial (its a little bit short)
Problem – I want to display the image using pygame. Normally this would read something like this:
monkey = pygame.image.load("monkey.jpg")
screen.blit(monkey,(0,0))
but instead I want to do use the image from the image file. So going from the first example it reads something like:
audio = MP3("born.mp3")
data = audio.tags['APIC:'].data
monkey = pygame.image.load(data)
but pygame throws an exception error because the data type of the variable ‘value’ is raw image data as a byte string.
Question – Is it possible to convert the byte string to some sort of image format so pygame can use it?
For python documentation on images – http://www.pygame.org/docs/ref/image.html
I’m not sure if it is even possible to do what I am asking so please forgive me!
Have you tried
pygame.image.fromstring()?note: since it’s raw data, you’ll need to know in advance a few details such as the resolution and colour depth.