FatalTerror Posted January 13, 2012 Share Posted January 13, 2012 Hi, I search how detect when the sound are stopped, when the music are finish. Exist ? Thanks Link to comment
Castillo Posted January 13, 2012 Share Posted January 13, 2012 I couldn't find such event, maybe there's a way to create it, but right now I can't think of one. Link to comment
mjau Posted January 14, 2012 Share Posted January 14, 2012 pause it instead and use this https://wiki.multitheftauto.com/wiki/IsSoundPaused Link to comment
Castillo Posted January 14, 2012 Share Posted January 14, 2012 Finished and Paused is a different thing. Link to comment
arezu Posted January 14, 2012 Share Posted January 14, 2012 im testing it right now, i'll be back when im done Link to comment
50p Posted January 14, 2012 Share Posted January 14, 2012 Long time ago I made a patch for that. I wrote onClientSoundStop and onClientSoundPlay with arguments but it was never amended. The only way I can think of is creating your own events, setting a timer at the same time as starting sounds, timer will trigger the sound event. Use getSoundLength to get sounds length and the interval for timer. Link to comment
mjau Posted January 14, 2012 Share Posted January 14, 2012 Maybe suggest theese events to get implemented ? Link to comment
Castillo Posted January 14, 2012 Share Posted January 14, 2012 Long time ago I made a patch for that. I wrote onClientSoundStop and onClientSoundPlay with arguments but it was never amended.The only way I can think of is creating your own events, setting a timer at the same time as starting sounds, timer will trigger the sound event. Use getSoundLength to get sounds length and the interval for timer. This will work with sounds played from a file, not live streams, as the length is always 0 for live streams. Link to comment
arezu Posted January 14, 2012 Share Posted January 14, 2012 you can do getElementsByType("sound") and check when the number of sound elements changes, or use onClientElementDestroy example code (the onClientSoundPlay is not working 100%, but you didn't really want it soo.. dont mind it) addEventHandler("onClientElementDestroy", getRootElement(), function() if(getElementType(source) == "sound")then outputChatBox("Sound stopped: "..tostring(source)) end end) --[[ local sounds = getElementsByType("sound") addEventHandler("onClientRender", getRootElement(), function() local s = getElementsByType("sound") if(#s > #sounds)then triggerEvent("onClientSoundPlay", getLocalPlayer(), s[#s]) end if(#s < #sounds)then for i = 1, #sounds do local theSound = searchTable(s, sounds[i]) if not theSound then triggerEvent("onClientSoundStop", getLocalPlayer(), sounds[i]) break end end end if(#s ~= #sounds)then sounds = s end end) addEvent("onClientSoundPlay", true) addEventHandler("onClientSoundPlay", getRootElement(), function(theSound) outputChatBox("Sound started playing: "..tostring(theSound)) end) addEvent("onClientSoundStop", true) addEventHandler("onClientSoundStop", getRootElement(), function(theSound) outputChatBox("Sound stopped playing: "..tostring(theSound)) end) function searchTable(tab, var) for k, v in pairs(tab) do if(v == var)then return v end end return false end --]] i commented out script in case you want to add onClientSoundPlay (you only need the onClientElementDestroy for what you asked) Link to comment
FatalTerror Posted January 14, 2012 Author Share Posted January 14, 2012 you can do getElementsByType("sound") and check when the number of sound elements changes, or use onClientElementDestroyexample code (the onClientSoundPlay is not working 100%, but you didn't really want it soo.. dont mind it) addEventHandler("onClientElementDestroy", getRootElement(), function() if(getElementType(source) == "sound")then outputChatBox("Sound stopped: "..tostring(source)) end end) --[[ local sounds = getElementsByType("sound") addEventHandler("onClientRender", getRootElement(), function() local s = getElementsByType("sound") if(#s > #sounds)then triggerEvent("onClientSoundPlay", getLocalPlayer(), s[#s]) end if(#s < #sounds)then for i = 1, #sounds do local theSound = searchTable(s, sounds[i]) if not theSound then triggerEvent("onClientSoundStop", getLocalPlayer(), sounds[i]) break end end end if(#s ~= #sounds)then sounds = s end end) addEvent("onClientSoundPlay", true) addEventHandler("onClientSoundPlay", getRootElement(), function(theSound) outputChatBox("Sound started playing: "..tostring(theSound)) end) addEvent("onClientSoundStop", true) addEventHandler("onClientSoundStop", getRootElement(), function(theSound) outputChatBox("Sound stopped playing: "..tostring(theSound)) end) function searchTable(tab, var) for k, v in pairs(tab) do if(v == var)then return v end end return false end --]] i commented out script in case you want to add onClientSoundPlay (you only need the onClientElementDestroy for what you asked) It work... big thanks 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