Jump to content

get for radio song name


papam77

Recommended Posts

  • Discord Moderators
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 by Guest
Link to comment
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?

Link to comment

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) 

Link to comment
  • Discord Moderators

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.

Link to comment

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.

Link to comment
  
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

Link to comment

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 
) 

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