[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] duration of song



Upon further experimentation I have found that this method does only work for .ogg and .wav files but not .mp3 files and such.
 
I can tell the size of the file in bytes simply by viewing details of the file in a window but I was wanting to use different sound files (including some the user could load) and thus I needed a way for the program to determine the duration (in seconds) of the music file since the music file being played would vary.
 
Jason
----- Original Message -----
Sent: Saturday, July 14, 2007 4:16 AM
Subject: Re: [pygame] duration of song

On 7/14/07, Dave LeCompte (really) <dave@xxxxxxxxxxxx> wrote:
"Ian Mallett" <geometrian@xxxxxxxxx> wrote:

> On 7/13/07, Jason Coggins <jcoggins828@xxxxxxxxxxx> wrote:
>>
>> Actually I was thinking of using the length of the music played as a
>> variable in the program.

> my_sound = pygame.mixer.sound([filename])
> number_of_seconds_long = my_sound.get_length()

That works for OGG and WAV sounds, but does not work for other music
files, like MP3, MOD, and MIDI, right?

Oh, opps.  You're probably right.  I'm curious now, why don't you know the length of the file?

The only thing I can think of is:
- play the music through pygame.mixer.music.play ()
- monitor the playback time with pygame.mixer.music.get_pos()
- when pygame.mixer.music.get_busy() returns False, you know how long the
music file was. If it helps, you'll know for next time.

That's probably not very helpful, either.


Which file format are you using for your music? Perhaps there is another
Python library that you can use to get the run length of your file.

-Dave LeCompte