MRmihailZH Posted January 28, 2021 Share Posted January 28, 2021 How do I rewind a song if it is launched via a URL? If you use setSoundPosition, the song can be rewound only to the already loaded part of the song, and this is a maximum of 2-3 seconds Link to comment
MRmihailZH Posted January 28, 2021 Author Share Posted January 28, 2021 6 minutes ago, Patrick said: I pause the audio before setting the position Link to comment
SpecT Posted January 28, 2021 Share Posted January 28, 2021 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. 1 Link to comment
MRmihailZH Posted January 28, 2021 Author Share Posted January 28, 2021 How can I download a song? @SpecT Link to comment
SpecT Posted January 28, 2021 Share Posted January 28, 2021 10 hours ago, MRmihailZH said: How can I download a song? @SpecT Client: local songPlaying function gotSong(musicData) local fileName = "temp.mp3" local tmpFile = fileCreate(fileName) fileWrite(tmpFile,musicData) fileClose(tmpFile) songPlaying = playSound(fileName) end addEvent("gotSong",true) addEventHandler("gotSong", root, gotSong) function seekStuff(cmd, seek) if songPlaying then setSoundPosition(songPlaying, seek) outputChatBox("Setting to "..seek.." seconds") end end addCommandHandler("seek",seekStuff) Server: function dlSong(thePlayer) fetchRemote("https://someURL.com/randomSong.mp3",handleSong, "", false, thePlayer ) end addCommandHandler("alo",dlSong) function handleSong(data,err,player) if err ~= 0 then return outputChatBox("We got a problem", player) end outputChatBox("Sending song data to client...", player) triggerClientEvent(player, "gotSong", player, data) end 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! 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now