Audio file length


Hi there,
I'm trying to create a game with a big circle that changes in size to the beat of a song. The audio files aren't imported into the game because i want people to be able to use their own files. I've succesfully managed to load a list of all songs in a certain folder, and i'm using the audio_create_stream function to play the sound. But this doesn't laod the whole file into game maker at once, so although it plays perfectly, i can't get the length or track position of the audio.
Is there any way to get the length of an audio file which is stored on the computer? I was thinking about using buffers but I have no idea how to import audio into one and how I can make a sound within game maker from the buffer.
Any help on working with audio would be appreciated, thanks.


In order to play audio from buffers, the data loaded must be raw (PCM) format. So to do that, you'd first have to decode the audio file, which I'm not sure there's a way to do in pure GML. You might have to use an extension, or prepare the audio files as PCM/WAV beforehand, and provide a little WAV format decoder.

If you're open to using an extension, I recently released an extension (windows only) that is able to load up an OGG file and return the duration of the track (in seconds). The extension is built to visualize audio waveforms, it happens to include a function for grabbing the duration of the song, which I think you can use: (more usage details on the itch page linked in the marketplace asset description, extension is free).

In your case, you'd do:

var oggfile = aviz_create("<path to music file>.ogg");
duration = aviz_get_duration(oggfile);
The variable "duration" will now hold the track length in seconds.