How to get time position of sound?

It is necessary to determine at what time position the audio is, that is, to get, for example, 36.2 seconds.

2 Likes

Sound.TimePosition is a readable property that is just this, the position of the playback head, something between 0 and Sound.TimeLength.

2 Likes

I read some articles and found that in some cases it outputs 0, it seems to be due to the fact that it is processed only on the client. But I want to use the server script to check whether the sound is at some mark when playing.

I’m pretty sure it’s always been like this. Sound programming logic is mostly done client-side. You can place sounds and start/stop them from Server code, but that’s about it. The server is just relaying these events to all clients, servers don’t actually play the sounds.

You can probably create some sort of function/object that keeps track of a sounds time position using os.clock(), which has high precision and doesn’t need to be linked to a “since epoch”.

Possible idea is after the play function is called on the instance you set an initial time and call a function whenever you need the time, which returns a delta time between initial and now. I.e. SoundTracker:GetTimePosition()

There’s probably better ways to do this, so I’m not too sure.

But the TimePosition works and is defined as it should, although I ran it on a server script.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.