Jump to content

[HELP] Music player GUI, Stack Overflow


NotAvailable

Recommended Posts

Hi,

Im working on a music player GUI.

But when i press the ON button, It says in debug:

ERROR: audio/audio_c.lua:14: Stack Overflow

Here is my code(client):

addEventHandler("onClientResourceStart",resourceRoot, 
    function() 
  
        window = guiCreateWindow(15,306,121,48,"Audio Options",false) 
guiWindowSetSizable(window,false) 
        on = guiCreateButton(9,24,40,15,"on",false,window) 
        addEventHandler ( "onClientGUIClick", on, playSound, false ) 
        off = guiCreateButton(64,25,40,14,"off",false,window) 
        addEventHandler ( "onClientGUIClick", off, stopSound, false ) 
    end 
) 
  
function playSound () 
local sound = playSound("cripsnbloods.mp3", false) 
setSoundVolume(sound, 0.5) 
end 
  
function stopSound () 
 setSoundPaused(sound, true) 
end 
  
  

I dont know whats the problem,

Regards,

Jesseunit

Link to comment

oh i see..

you are overwriting default playSound function with your own - you called it playSound.

so if you are using playSound in playSound - you got an endless loop.

rename your functions

also i think you should use stopSound, not setSoundPaused - as you are not unpausing it - which means you are creating new sound everytime you click play.

also you should block play if sound is playing (use global variable like: isPlaying or isElement(sound) should be good too)

Link to comment
oh i see..

you are overwriting default playSound function with your own - you called it playSound.

so if you are using playSound in playSound - you got an endless loop.

rename your functions

also i think you should use stopSound, not setSoundPaused - as you are not unpausing it - which means you are creating new sound everytime you click play.

also you should block play if sound is playing (use global variable like: isPlaying or isElement(sound) should be good too)

Ok, thanks! :D

Link to comment
post your code again
addEventHandler("onClientResourceStart",resourceRoot, 
    function() 
        window = guiCreateWindow(15,306,121,48,"Audio Options",false) 
        guiWindowSetSizable(window,false) 
        on = guiCreateButton(9,24,40,15,"on",false,window) 
        addEventHandler ( "onClientGUIClick", on, startSound, false ) 
        off = guiCreateButton(64,25,40,14,"off",false,window) 
        addEventHandler ( "onClientGUIClick", off, lol, false ) 
    end 
    ) 
     
function startSound () 
local sound = playSound("armysound.mp3", false) 
setSoundVolume(sound, 1.0) 
end 
  
  
function lol () 
if isElement(sound) == playing then 
  setSoundVolume(sound, 0.0) 
end 
end 

Link to comment

i said doing this like that

  
function startSound () 
local sound = playSound("armysound.mp3", false) 
setSoundVolume(sound, 1.0) 
end 
  
  
function lol () 
if isElement(sound) == playing then 
  setSoundVolume(sound, 0.0) 
end 
end 
  

will make new sound created every play - you are only muting sound but its actually playing. in some extreme conditions it will be slowing down pc and may cause crash too.

also i said use global variable OR isElement, you mixed it without thinking what are you really doing..

  
if isElement(sound) == playing then 
  

FIX:

  
function startSound() 
  if not isElement(sound) then -- if our sound is not existing we can create one 
    sound = playSound("armysound.mp3", false) -- can't be local, because there will be no way to stop it (okay, there is one way but.. whatever) 
    setSoundVolume(sound, 1.0) -- i think this is default volume.. do we really need it? 
  end 
end 
  
  
function lol() 
  if isElement(sound) then -- if our sound is existing - we will stop it 
    stopSound(sound) 
  end 
end 
  

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