MIX_PlayTrack(3)
π MIX_PlayTrack(3) π
okay bestie, sit down, hydrate, because we're talking about MIX_PlayTrack β that's the baddie from the SDL_mixer3 FUNCTIONS lineup, and she's literally the reason your track goes from silence to slay. πβ¨
β¨ NAME β¨
MIX_PlayTrack β Start (or restart) mixing a track for playback.
π SYNOPSIS π
#include <SDL3_mixer/SDL_mixer.h>
bool MIX_PlayTrack(MIX_Track *track, SDL_PropertiesID options);
π¦ DESCRIPTION π¦
So here's the tea. The track is gonna use whatever input was last assigned to it when it plays. And no cap β an input must be assigned to this track or this function will fail. Periodt. π
Wanna assign an input? You do that with calls to MIX_SetTrackAudio(), MIX_SetTrackAudioStream(), or MIX_SetTrackIOStream(). Pick your fighter.
If the track is already playing, or paused, this will restart the track with the newly-specified parameters. Like, full reset, new fit, new energy. π₯
Now β there are several parameters, and more may be added in the future, so they're specified with an SDL_PropertiesID. The parameters have reasonable defaults, and specifying a 0 for options will choose defaults for everything. Easy mode, we love her.
SDL_PropertiesID are discussed in SDL's documentation at https://wiki.libsdl.org/SDL3/CategoryProperties.
These are the supported properties, and yes, we're doing all of them, no skipping:
MIX_PROP_PLAY_LOOPS_NUMBERβ The number of times to loop the track when it reaches the end. A value of1will loop to the start one time. Zero will not loop at all. A value of-1requests infinite loops. If the input is not seekable and this value isn't zero, this function will report success but the track will stop at the point it should loop. Default0.MIX_PROP_PLAY_MAX_FRAME_NUMBERβ Mix at most to this sample frame position in the track. This will be treated as if the input reach EOF at this point in the audio file. If-1, mix all available audio without a limit. Default-1.MIX_PROP_PLAY_MAX_MILLISECONDS_NUMBERβ The same as using theMIX_PROP_PLAY_MAX_FRAME_NUMBERproperty, but the value is specified in milliseconds instead of sample frames. If both properties are specified, the sample frames value is favored. Default-1.MIX_PROP_PLAY_START_FRAME_NUMBERβ Start mixing from this sample frame position in the track's input. A value<= 0will begin from the start of the track's input. If the input is not seekable and this value is> 0, this function will report failure. Default0.MIX_PROP_PLAY_START_MILLISECOND_NUMBERβ The same as using theMIX_PROP_PLAY_START_FRAME_NUMBERproperty, but the value is specified in milliseconds instead of sample frames. If both properties are specified, the sample frames value is favored. Default0.MIX_PROP_PLAY_LOOP_START_FRAME_NUMBERβ If the track is looping, this is the sample frame position that the track will loop back to; this lets one play an intro at the start of a track on the first iteration, but have a loop point somewhere in the middle thereafter. A value<= 0will begin the loop from the start of the track's input. Default0.MIX_PROP_PLAY_LOOP_START_MILLISECOND_NUMBERβ The same as using theMIX_PROP_PLAY_LOOP_START_FRAME_NUMBERproperty, but the value is specified in milliseconds instead of sample frames. If both properties are specified, the sample frames value is favored. Default0.MIX_PROP_PLAY_FADE_IN_FRAMES_NUMBERβ The number of sample frames over which to fade in the newly-started track. The track will begin mixing silence and reach full volume smoothly over this many sample frames. If the track loops before the fade-in is complete, it will continue to fade correctly from the loop point. A value<= 0will disable fade-in, so the track starts mixing at full volume. Default0.MIX_PROP_PLAY_FADE_IN_MILLISECONDS_NUMBERβ The same as using theMIX_PROP_PLAY_FADE_IN_FRAMES_NUMBERproperty, but the value is specified in milliseconds instead of sample frames. If both properties are specified, the sample frames value is favored. Default0.MIX_PROP_PLAY_FADE_IN_START_GAIN_FLOATβ If fading in, start fading from this volume level.0.0fis silence and1.0fis full volume, every in between is a linear change in gain. The specified value will be clamped between0.0fand1.0f. Default0.0f.MIX_PROP_PLAY_APPEND_SILENCE_FRAMES_NUMBERβ At the end of mixing this track, after all loops are complete, append this many sample frames of silence as if it were part of the audio file. This allows for apps to implement effects in callbacks, like reverb, that need to generate samples past the end of the stream's audio, or perhaps introduce a delay before starting a new sound on the track without having to manage it directly. A value<= 0generates no silence before stopping the track. Default0.MIX_PROP_PLAY_APPEND_SILENCE_MILLISECONDS_NUMBERβ The same as using theMIX_PROP_PLAY_APPEND_SILENCE_FRAMES_NUMBERproperty, but the value is specified in milliseconds instead of sample frames. If both properties are specified, the sample frames value is favored. Default0.MIX_PROP_PLAY_HALT_WHEN_EXHAUSTED_BOOLEANβ If true, when input is completely consumed for the track, the mixer will mark the track as stopped (and call any appropriateMIX_TrackStoppedCallback, etc); to play more, the track will need to be restarted. If false, the track will just not contribute to the mix, but it will not be marked as stopped. There may be clever logic tricks this exposes generally, but this property is specifically useful when the track's input is anSDL_AudioStreamassigned viaMIX_SetTrackAudioStream(). Setting this property to true can be useful when pushing a complete piece of audio to the stream that has a definite ending, as the track will operate like any other audio was applied. Setting to false means as new data is added to the stream, the mixer will start using it as soon as possible, which is useful when audio should play immediately as it drips in: new VoIP packets, etc. Note that in this situation, if the audio runs out when needed, there _will_ be gaps in the mixed output, so try to buffer enough data to avoid this when possible. Note that a track is not consider exhausted until all its loops and appended silence have been mixed (and also, that loops don't mean anything when the input is an AudioStream). Defaulttrue.MIX_PROP_PLAY_START_ORDER_NUMBERβ This is a special-case property that most apps can ignore. For mod file formats, start mixing from a specific "order" index instead of the start of the file. A value< 0will cause this property to be ignored. If the decoder doesn't support this property, it will also be ignored. If this property is _not_ ignored, theMIX_PROP_PLAY_START_FRAME_NUMBERandMIX_PROP_PLAY_START_MILLISECOND_NUMBERproperties will be ignored instead. Default-1. Since SDL_mixer 3.2.2.
π¨ bestie heads up: if this function fails, mixing of this track will not start (or restart, if it was already started). No half-sends here, she's an all-or-nothing girlie.
π FUNCTION PARAMETERS π
trackβ the track to start (or restart) mixing.optionsβ a set of properties that control playback. May be zero.
π RETURN VALUE π
Returns true on success, false on error; call SDL_GetError() for details. So like, always check, okay? Don't be out here ignoring your return values. π
π§΅ THREAD SAFETY π§΅
It is safe to call this function from any thread. Main character energy that works everywhere. β¨
πΈ AVAILABILITY πΈ
This function is available since SDL_mixer 3.0.0.
π SEE ALSO π
and that's the whole page, bestie, go make some noise π§π
this iconic little manual page is brought to you by SDL_mixer, version SDL_mixer 3.2.4 β mwah, kisses, see u next commit π π«Ά
π¦ where this page comes from
- fedora 44: SDL3_mixer-doc 3.2.4-3.fc44 Β· Zlib AND (GPL-2.0-or-later OR LGPL-2.0-or-later)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms