papam77 Posted September 29, 2013 Posted September 29, 2013 Hello, How can get song name from radio? I saw it on some servers, so it is possible. This radio is already giving the song name to mp3 players in PC but i need to get song name in a game. So how? Radio: http://www.181.fm/winamp.pls?station=18 ... 0(Top%2040)&file=181-power.pls
Discord Moderators Zango Posted September 29, 2013 Discord Moderators Posted September 29, 2013 https://wiki.multitheftauto.com/wiki/GetSoundMetaTags
papam77 Posted September 29, 2013 Author Posted September 29, 2013 And how can use it if is it online radio? Give me an example please
Discord Moderators Zango Posted September 29, 2013 Discord Moderators Posted September 29, 2013 (edited) local sound_Radio = playSound ('http://www.181.fm/winamp.pls?station=181-power&style=&description=Power%20181%20(Top%2040') function outputSoundMeta (sound) local tTags = getSoundMetaTags (sound_Radio) if tTags then for tag, value in pairs (tTags) do outputChatBox (string.format('Artist: %s | Title: %s', tag, value)) end return true end return false end addCommandHandler ("soundinfo", outputSoundMeta) This code will reveal that audio streams take use of stream_name as radio station title and stream_title as the currently playing data, which you want. Assuming this radio has formatted their songs consistently, you could use " - " to identify the track artist and title, respectively. Edited September 29, 2013 by Guest
Discord Moderators Zango Posted September 29, 2013 Discord Moderators Posted September 29, 2013 onClientSoundChangedMeta function onClientSoundChangedMeta (streamTitle) if streamTitle then outputChatBox (streamTitle) end return true end addEventHandler ('onClientSoundChangedMeta', sound_Radio, onClientSoundChangedMeta)
papam77 Posted September 29, 2013 Author Posted September 29, 2013 function startMusic() setRadioChannel(0) song = playSound("http://www.181.fm/winamp.pls?station=181-power&style=&description=Power%20181%20(Top%2040)&file=181-power.pls") end function makeRadioStayOff() setRadioChannel(0) cancelEvent() end function outputSoundMeta (sound) local tTags = getSoundMetaTags (song) if tTags then for tag, value in pairs (tTags) do outputChatBox (string.format('Artist: %s | Title: %s', tag, value)) end return true end return false end addCommandHandler ("soundinfo", outputSoundMeta) function onClientSoundChangedMeta (streamTitle) local tTags = getSoundMetaTags (song) if tTags then for tag, value in pairs (tTags) do outputChatBox (string.format('Artist: %s | Title: %s', tag, value)) end end return true end addEventHandler ('onClientSoundChangedMeta', song, onClientSoundChangedMeta) function toggleSong() if not songOff then setSoundVolume(song,0) songOff = true outputChatBox("#ffffffRadio state = #ff0000OFF", 255,255,255, true ) removeEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) else setSoundVolume(song,1) songOff = false setRadioChannel(0) outputChatBox("#ffffffRadio state = #00ff00ON", 255,255,255, true ) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) end end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),startMusic) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) addEventHandler("onClientPlayerVehicleEnter",getRootElement(),makeRadioStayOff) addCommandHandler("musicmusic",toggleSong) bindKey("F10","down","musicmusic") addEventHandler("onClientResourceStop",getResourceRootElement(getThisResource()),startMusic) I edited it a bit and what's the problem? Why it doesn't show the song name when song get changed?
Discord Moderators Zango Posted September 29, 2013 Discord Moderators Posted September 29, 2013 You are trying to bind onClientSoundChangedMeta to "song" which isn't initialised yet. Move the addEventHandler below song = playSound
papam77 Posted September 29, 2013 Author Posted September 29, 2013 Below? Like this? function startMusic() setRadioChannel(0) song = playSound("http://www.181.fm/winamp.pls?station=181-power&style=&description=Power%20181%20(Top%2040)&file=181-power.pls") end addEventHandler ('onClientSoundChangedMeta', song, onClientSoundChangedMeta) function makeRadioStayOff() setRadioChannel(0) cancelEvent() end function outputSoundMeta (sound) local tTags = getSoundMetaTags (song) if tTags then for tag, value in pairs (tTags) do outputChatBox (string.format('Artist: %s | Title: %s', tag, value)) end return true end return false end addCommandHandler ("soundinfo", outputSoundMeta) function onClientSoundChangedMeta (streamTitle) local tTags = getSoundMetaTags (song) if tTags then for tag, value in pairs (tTags) do outputChatBox (string.format('Artist: %s | Title: %s', tag, value)) end end return true end function toggleSong() if not songOff then setSoundVolume(song,0) songOff = true outputChatBox("#ffffffRadio state = #ff0000OFF", 255,255,255, true ) removeEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) else setSoundVolume(song,1) songOff = false setRadioChannel(0) outputChatBox("#ffffffRadio state = #00ff00ON", 255,255,255, true ) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) end end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),startMusic) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) addEventHandler("onClientPlayerVehicleEnter",getRootElement(),makeRadioStayOff) addCommandHandler("musicmusic",toggleSong) bindKey("F10","down","musicmusic") addEventHandler("onClientResourceStop",getResourceRootElement(getThisResource()),startMusic)
Discord Moderators Zango Posted September 29, 2013 Discord Moderators Posted September 29, 2013 When MTA loads a script, Lua checks for syntax errors and declares all variables and functions. If you place something outside a function, it's called in this process. But this stuff takes place before onClientResourceStart - which is the point where everything is ready. You need to move it into the function startMusic, at the bottom.
papam77 Posted September 29, 2013 Author Posted September 29, 2013 But there's problem if is song called somebody ft. somebody it looks like somebody f/somebody. Why?
Discord Moderators Zango Posted September 29, 2013 Discord Moderators Posted September 29, 2013 The data returned has nothing to do with MTA. If you open the stream yourself, you'll find that it looks like that as well. It's how they chose to broadcast the songs on their radio.
Dealman Posted September 30, 2013 Posted September 30, 2013 Every streamed file will return different values, it depends on whether the author set the tags properly or not. Some use the tags as means of advertisement and others have them set up properly. Also for internet radios, you might have to use stream_name and stream_title instead of artist/title. Feel free to check out my Radio(Link in signature) for code example on how to achieve this.
papam77 Posted September 30, 2013 Author Posted September 30, 2013 And is possible to do something like local ft = outputChatBox() if ( ft == f/ ) then -- ??? end And change it, but dunno how.
Discord Moderators Zango Posted September 30, 2013 Discord Moderators Posted September 30, 2013 You can use a function such as string.gsub to search for "f/" and replace it with "ft. ". function formatTrackTitle (strTitle) return strTitle:gsub ('f/', 'ft. ') end
papam77 Posted September 30, 2013 Author Posted September 30, 2013 function startMusic() setRadioChannel(0) song = playSound("http://www.181.fm/winamp.pls?station=181-power&style=&description=Power%20181%20(Top%2040)&file=181-power.pls") addEventHandler ('onClientSoundChangedMeta', song, onClientSoundChangedMeta) end function makeRadioStayOff() setRadioChannel(0) cancelEvent() end function onClientSoundChangedMeta (streamTitle, strTitle) local tTags = getSoundMetaTags (song) local c = 255,255,255,true if tTags then for tag, value in pairs (tTags) do outputChatBox (string.format('#ffffffArtist: %s | Title: %s',tag, value),255,255,255,true) end return strTitle:gsub ('f/', 'ft. ') end return true end function toggleSong() if not songOff then setSoundVolume(song,0) songOff = true outputChatBox("#ffffffRadio state = #ff0000OFF", 255,255,255, true ) removeEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) else setSoundVolume(song,1) songOff = false setRadioChannel(0) outputChatBox("#ffffffRadio state = #00ff00ON", 255,255,255, true ) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) end end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),startMusic) addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff) addEventHandler("onClientPlayerVehicleEnter",getRootElement(),makeRadioStayOff) addCommandHandler("musicmusic",toggleSong) bindKey("F10","down","musicmusic") addEventHandler("onClientResourceStop",getResourceRootElement(getThisResource()),startMusic) Still f/somebody
myonlake Posted September 30, 2013 Posted September 30, 2013 Because you're returning it as a value, which makes no sense as you are outputting the chatbox message before the return. Besides, you don't need to return any value at all. addEventHandler("onClientResourceStart", resourceRoot, function() setRadioChannel(0) song = playSound("http://www.181.fm/winamp.pls?station=181-power&style=&description=Power%20181%20(Top%2040)&file=181-power.pls") addEventHandler("onClientSoundChangedMeta", song, onClientSoundChangedMeta) bindKey("F10", "down", "musicmusic") end ) function makeRadioStayOff() setRadioChannel(0) cancelEvent() end addEventHandler("onClientPlayerRadioSwitch", root, makeRadioStayOff) addEventHandler("onClientPlayerVehicleEnter", root, makeRadioStayOff) function onClientSoundChangedMeta(streamTitle) local tTags = getSoundMetaTags(source) if (tTags) then for tag,value in pairs(tTags) do outputChatBox(string.gsub(string.format('#ffffffArtist: %s | Title: %s', tag, value), "f/", "ft. "), 255, 255, 255, true) end end end addCommandHandler("musicmusic", function(cmd) if (not songOff) then setSoundVolume(song, 0) songOff = true outputChatBox("#ffffffRadio state = #ff0000OFF", 255, 255, 255, true) removeEventHandler("onClientPlayerRadioSwitch", root, makeRadioStayOff) else setSoundVolume(song, 1) songOff = false setRadioChannel(0) outputChatBox("#ffffffRadio state = #00ff00ON", 255, 255, 255, true) addEventHandler("onClientPlayerRadioSwitch", root, makeRadioStayOff) end end )
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