SDL Wiki
[ front page | index | search | recent changes | git repo | offline html ]
(This function is part of SDL_mixer, a separate library from SDL.)

MIX_GetAudioDuration

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

Header File

Defined in <SDL3_mixer/SDL_mixer.h>

Syntax

Sint64 MIX_GetAudioDuration(MIX_Audio *audio);


#define MIX_DURATION_UNKNOWN -1
#define MIX_DURATION_INFINITE -2

Function Parameters

MIX_Audio * audio the audio to query.

Return Value

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

Remarks

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.

Thread Safety

It is safe to call this function from any thread.

Version

This function is available since SDL_mixer 3.0.0.


CategoryAPI, CategoryAPIFunction, CategorySDLMixer


[ edit | delete | history | feedback | raw ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.