botshara Posted September 10, 2016 Posted September 10, 2016 Hello, Im making radio script and I want get stream title from radios, but problem is that I get very big perfomance lags when I start my radio. Im using onClientRender Handler and getSoundMetaTags function to get stream title. Without this function script using only ~2% CPU but with this function (getSoundMetaTags) script using ~20% CPU. There is any alternative using onClientRender Handler and dont get perfomance lags ?
Walid Posted September 10, 2016 Posted September 10, 2016 post your code here Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
botshara Posted September 10, 2016 Author Posted September 10, 2016 addEventHandler ( "onClientRender", root, function ( ) if isPedInVehicle ( localPlayer ) then local vehicle = getPedOccupiedVehicle ( localPlayer ) if not vehicle then return end local radioID = getElementData ( vehicle, "radioID" ) if radioID and radioID >= 0 then local sound = getSoundsBlyat[vehicle] if isElement(sound) and sound and getSoundMetaTags ( sound ) then song = getSoundMetaTags ( sound )["stream_title"] end and so on .......
Jusonex Posted September 10, 2016 Posted September 10, 2016 The reason why getSoundMetaTags is slow is that it has to read a piece of the stream to get the desired data. As a fix, you should call getSoundMetaTags only once or, if you need to update it from time to time, use a timer. E.g.: local streamTitle = "" setTimer( function() streamTitle = getSoundMetaTags(sound).streamTitle end, 5000, 1 ) -- Update every 5 seconds addEventHandler("onClientRender", root, function() -- Do whatever you want to do with 'streamTitle' end ) 1
Walid Posted September 10, 2016 Posted September 10, 2016 (edited) What about this (untested) addEventHandler("onClientVehicleEnter", getRootElement(), function(player, seat) if player == localPlayer then local radioID = getElementData (source, "radioID" ) if radioID and radioID >= 0 then local sound = getSoundsBlyat[source] if sound and isElement(sound) then local meta = getSoundMetaTags(sound) title = meta.title end end end end ) -- "onClientPlayerRadioSwitch" addEventHandler("onClientPlayerRadioSwitch", getLocalPlayer(), function (station) if isPedInVehicle ( localPlayer ) then if station ~= 0 then local vehicle = getPedOccupiedVehicle ( localPlayer ) -- use the same code here and make sure you keep title (global variable) end end end ) addEventHandler ( "onClientRender", root, function ( ) if title then -- draw sound title here end and Edited September 10, 2016 by Walid 1 Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
botshara Posted September 10, 2016 Author Posted September 10, 2016 Thanks for support. I Tryed with setTimer like said @Jusonex and works very good, CPU usage from 20% to 2% for my radio resource. Thumbs up guys
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