MIX_SetTrac...ackPosition(3)
π MIX_SetTrac...ackPosition(3) π
okay bestie, sit down, we're doing SDL_mixer3 FUNCTIONS today and this one is lowkey iconic. it's the "teleport my track to a different spot in the audio" function. no cap.
β¨ NAME β¨
MIX_SetTrackPlaybackPosition β seek a playing track to a new position in its input. that's it, that's the whole vibe: move the playhead, keep the song going. π
πΈ SYNOPSIS πΈ
#include <SDL3_mixer/SDL_mixer.h>
bool MIX_SetTrackPlaybackPosition(MIX_Track *track, Sint64 frames);
π¦ DESCRIPTION π¦
first things first, do not confuse this with MIX_SetTrack3DPosition(), okay?? that one is about where the track sits in 3D space β like, which direction the sound comes from. THIS one is about where you are in the actual audio data. two completely different girls, don't mix them up π
so on a playing track, the next time the mixer runs, it starts mixing from your new position. the way that this works is genuinely so clean.
here's the key thing: position is defined in _sample frames_ of decoded audio, not units of time. that's on purpose!! it's how you get sample-perfect mixing. want to think in time instead? go use MIX_TrackMSToFrames() to get the approximate sample frames for a given tick. periodt.
now the requirements, listen up π this function needs an input that can seek, so:
- it can not be used if the input was set with
MIX_SetTrackAudioStream() - you also need an audio file format that allows seeking
and some of SDL_mixer's decoders for certain file formats just... don't offer seeking at all, or they can only seek to times rather than exact sample frames β in which case your final position may be off by some amount of sample frames. so please check your audio data, and file bug reports if appropriate. fr fr.
oh and it's totally legal to call this on a track that's stopped β but a future call to MIX_PlayTrack() will reset the start position anyhow. so like, whatever. paused tracks, though? those will resume at the new input position. slay. β¨
ngl, the seek-precision thing is the one to watch out for. if your decoder can't do exact frames, you're getting close enough, not exact. check your data!!
π FUNCTION PARAMETERS π
trackβ the track to change. the one you're moving.framesβ the sample frame position to seek to. where the playhead is going, bestie.
π RETURN VALUE π
Returns true on success, false on error β and if it's error o'clock, call SDL_GetError() for the details. she'll tell you what went wrong. π
π₯ THREAD SAFETY π₯
It is safe to call this function from any thread. multitask, queen. π
π AVAILABILITY π
This function is available since SDL_mixer 3.0.0.
β SEE ALSO β
MIX_GetTrackPlaybackPosition(3)β the other half of the duo, she reads, this one writes π«Ά
okay that's the page!!! go forth and seek responsibly π§
mwah β this was brought to you by SDL_mixer, version 3.2.4, and yeah the date situation is that classic SDL_mixer 3.2.4 footer energy, so we're signing off with the source and version only, as the universe intended. bye bestie ππΈπ
π¦ 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