audio_sound_length

This function returns the length of the given sound in seconds.

The sound can either be a referenced from index for an individual sound instance being played which has been stored in a variable when using any of the audio_play_sound_ functions, or an actual sound asset from The Asset Browser.

 

Syntax:

audio_sound_length(index);

ArgumentTypeDescription
indexSound Asset or Sound Instance IDThe index of the sound to check.

 

Returns:

Real

 

Example:

var _len = audio_sound_length(snd_Beam);
audio_play_sound(snd_Beam, 1, false);
alarm[0] = game_get_speed(gamespeed_fps) * _len;

The above code gets the length (in seconds) of the sound indexed in the variable snd_Beam, then plays the sound and sets an alarm to go off when the sound has finished playing using the length of the sound to calculate the time needed for the alarm.

NOTE The alarm will trigger at around the same time the sound stops playing. You can also use the Audio Playback Ended event if you need to execute some code at the exact time that playback of the audio ends.