Pygame sound music files

Pygame sound music files

Postby metulburr » Sun Apr 20, 2014 11:27 am

I tried coming up with a way to get the toal length of tracks in a directory with pygame music, but it appears that it does not load it all in ram, thus you cannot without playing it?

So then i tried to load the mp3 file in sound since that does have an option to get_length(), however sound will not load mp3 files, must be ogg or wav. So then i converted the mp3 to wav, and it finally gave me the length of the song.

So questions comes to mind...
Why would you use mp3 files at all then, If wav files can be loaded as both music and sounds? Is there a loss in quality in wav files as opposed to mp3?
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1470
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Pygame sound music files

Postby Mekire » Sun Apr 20, 2014 2:29 pm

Wav files are generally much bigger. You might look into some modules that can inspect mp3 metadata.
I was just experimenting with this:
https://bitbucket.org/lazka/mutagen/overview

It is really easy to use but unfortunately there is no python 3 version.
Some guy was trying to port it but the supposedly python 3 compatible version he made, wasn't.

Anyway its usage is straight forward:
Code: Select all
>>> from mutagen import mp3
>>> music = mp3.MP3("Kalinka.mp3")
>>> music.info.length
269.635875
>>> minutes, seconds = divmod(_, 60)
>>> print("{}:{:.2f}".format(int(minutes), seconds))
4:29.64
>>>

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Pygame sound music files

Postby metulburr » Sun Apr 20, 2014 3:35 pm

thanks
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1470
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron