Jump to content

destroy sound


Fabioxps

Recommended Posts

:arrowdown: stop the music at the end, before destroying?

  
getSoundLength 
getSoundPosition 
setSoundPaused 
setSoundPosition --position 0 
  

not destroy the music and resumes it

element playSound ( string soundPath, [ bool looped = false ] ) 

I do not want to use the agurmento loop to resume music :arrowleft:

:idea:

Link to comment
I want to repeat the sound and stop not to destroy.

help?

first you've to define the sound as variable

  
local mySound = playSound("You Path Here", bool loop) 

for loop do true or false (True means repeat when finnsh, false don't repeat)

if you want to stop the sound use stopSound function

stopSound(mySound) 

Link to comment

The only way I found for not destroy the element when the music run out, was the following:

sound = playSound("...") 
setSoundPaused(sound,true) 
  
function refresh() 
    if getSoundPosition(sound)+1 < getSoundLength(sound) then 
        if not isSoundPaused(sound) then 
            setSoundPaused(sound,false) 
        end 
    else 
        setSoundPaused(sound,true) 
        removeEventHandler("onClientRender",root,refresh) 
    end 
end 
  
-- example of use 
addCommandHandler("cmd",function(cmd,subcmd) 
    if subcmd == "start" then 
        addEventHandler("onClientRender",root,refresh) 
    elseif subcmd == "restart" then 
        setSoundPosition(sound,0) 
        --addEventHandler("onClientRender",root,refresh) 
    elseif subcmd == "stop" then 
        removeEventHandler("onClientRender",root,refresh) 
        setSoundPaused(sound,true) 
        setSoundPosition(sound,0) 
    end 
end) 

If you use in server side you can using setTimer for doing the checking

Link to comment
The only way I found for not destroy the element when the music run out, was the following:
sound = playSound("...") 
setSoundPaused(sound,true) 
  
function refresh() 
    if getSoundPosition(sound)+1 < getSoundLength(sound) then 
        if not isSoundPaused(sound) then 
            setSoundPaused(sound,false) 
        end 
    else 
        setSoundPaused(sound,true) 
        removeEventHandler("onClientRender",root,refresh) 
    end 
end 
  
-- example of use 
addCommandHandler("cmd",function(cmd,subcmd) 
    if subcmd == "start" then 
        addEventHandler("onClientRender",root,refresh) 
    elseif subcmd == "restart" then 
        setSoundPosition(sound,0) 
        --addEventHandler("onClientRender",root,refresh) 
    elseif subcmd == "stop" then 
        removeEventHandler("onClientRender",root,refresh) 
        setSoundPaused(sound,true) 
        setSoundPosition(sound,0) 
    end 
end) 

If you use in server side you can using setTimer for doing the checking

I had already made their code this perfect thank you. <3

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...