Jump to content

How do I rewind a song?


Recommended Posts

setSoundPosition works when you seek to a part of the song which was loaded/downloaded.
Using it on sounds which are played from URL won't work fine if the connection is slow.
A solution could be to download and write the song in a temporary file and play it. Then you should be able to seek without problems.

  • Like 1
Link to comment
10 hours ago, MRmihailZH said:

How can I download a song? @SpecT


local songPlaying
function gotSong(musicData)
	local fileName = "temp.mp3"
	local tmpFile = fileCreate(fileName)
	songPlaying = playSound(fileName)
addEventHandler("gotSong", root, gotSong)

function seekStuff(cmd, seek)
	if songPlaying then
		setSoundPosition(songPlaying, seek)
		outputChatBox("Setting to "..seek.." seconds")


function dlSong(thePlayer)
	fetchRemote("https://someURL.com/randomSong.mp3",handleSong, "", false, thePlayer )

function handleSong(data,err,player)
	if err ~= 0 then
		return outputChatBox("We got a problem", player)
	outputChatBox("Sending song data to client...", player)
	triggerClientEvent(player, "gotSong", player, data)

Note: The song won't play immediately! Also it will generate some traffic to the server and between client-server because it has to transfer the music data.
But in the end you will be able to seek wherever you want the moment the song starts playing.
I don't know what your case is so I'm not sure if this way is efficient for you but it's an answer to your question.

*I wrote this stuff quickly so it could be done better I guess.
Hope this example is useful! ?

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...