Scroll to navigation

MIX_GetAudioDuration(3) SDL_mixer3 FUNCTIONS MIX_GetAudioDuration(3)

NAME

MIX_GetAudioDuration - Get the length of a MIX_Audio's playback in sample frames.

SYNOPSIS

#include <SDL3_mixer/SDL_mixer.h>
Sint64 MIX_GetAudioDuration(MIX_Audio *audio);


#define MIX_DURATION_UNKNOWN -1
#define MIX_DURATION_INFINITE -2

DESCRIPTION

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.

FUNCTION PARAMETERS

the audio to query.

RETURN VALUE

Returns the length of the audio in sample frames, or MIX_DURATION_UNKNOWN or MIX_DURATION_INFINITE.

THREAD SAFETY

It is safe to call this function from any thread.

AVAILABILITY

This function is available since SDL_mixer 3.0.0.

SDL_mixer 3.1.3 SDL_mixer