M MY Multiplayer: Wiki
Side
Kind

getSoundPosition

Shared

Returns the point in the track the sound is playing.

float|false getSoundPosition(sound sound)

Parameters

NameTypeDescription
soundsoundThe sound element. On the client a dui element also works, for the browser's sound.

Returns

The position in seconds, or false if the sound was not found.

On the server, the position is worked out from the time that has passed, and wraps back to the start when the sound loops.

Example

local music = playSound("sounds/track.mp3")

addEventHandler("onClientRender", root, function()
    local now = getSoundPosition(music) or 0
    local total = getSoundLength(music) or 1
    dxDrawRectangle(20, 20, 200 * now / total, 6, tocolor(255, 255, 255))
end)
NoteThis is the playback position, not the position in the world. For that, use getElementPosition.

See also