Get the length of a MIX_Audio's playback in sample frames.
Defined in <SDL3_mixer/SDL_mixer.h>
Sint64 MIX_GetAudioDuration(MIX_Audio *audio);
#define MIX_DURATION_UNKNOWN -1
#define MIX_DURATION_INFINITE -2
MIX_Audio * | audio | the audio to query. |
(Sint64) Returns the length of the audio in sample frames, or MIX_DURATION_UNKNOWN or MIX_DURATION_INFINITE.
This information is also available via the MIX_PROP_METADATA_DURATION_FRAMES_NUMBER property, but it's common enough to provide a simple accessor function.
This reports the length of the data in sample frames, so sample-perfect mixing can be possible. Sample frames are only meaningful as a measure of time if the sample rate (frequency) is also known. To convert from sample frames to milliseconds, use MIX_AudioFramesToMS().
Not all audio file formats can report the complete length of the data they will produce through decoding: some can't calculate it, some might produce infinite audio.
Also, some file formats can only report duration as a unit of time, which means SDL_mixer might have to estimate sample frames from that information. With less precision, the reported duration might be off by a few sample frames in either direction.
This will return a value >= 0 if a duration is known. It might also return MIX_DURATION_UNKNOWN or MIX_DURATION_INFINITE.
It is safe to call this function from any thread.
This function is available since SDL_mixer 3.0.0.