NotAvailable Posted October 17, 2010 Share Posted October 17, 2010 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
dzek (varez) Posted October 17, 2010 Share Posted October 17, 2010 your mp3 file is broken (even if winamp plays it correctly anyway) Link to comment
NotAvailable Posted October 17, 2010 Author Share Posted October 17, 2010 your mp3 file is broken (even if winamp plays it correctly anyway) Ok thanks ill try to fix it Link to comment
NotAvailable Posted October 17, 2010 Author Share Posted October 17, 2010 Nope its still the same: Link to comment
dzek (varez) Posted October 17, 2010 Share Posted October 17, 2010 send me full script with mp3 sound. Link to comment
NotAvailable Posted October 17, 2010 Author Share Posted October 17, 2010 (edited) send me full script with mp3 sound. Here: [LOCKED] Edited October 17, 2010 by Guest Link to comment
dzek (varez) Posted October 17, 2010 Share Posted October 17, 2010 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
NotAvailable Posted October 17, 2010 Author Share Posted October 17, 2010 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! Link to comment
NotAvailable Posted October 17, 2010 Author Share Posted October 17, 2010 Hmmm.... 1 thing. The 'off' button is not working Link to comment
dzek (varez) Posted October 17, 2010 Share Posted October 17, 2010 post your code again Link to comment
NotAvailable Posted October 17, 2010 Author Share Posted October 17, 2010 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
dzek (varez) Posted October 17, 2010 Share Posted October 17, 2010 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
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