Jump to content

Radio Gui


Mefisto_PL

Recommended Posts

I have a small problem.. I found a radio gui, but when I double click on the song, it doesn't stop, but when I click it again then sound is double played..

local sTations ={ 
    ["Power 181"] = "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription="; 
} 
  
function CreateRadioGui ( )         
        if ( guiGetVisible ( RadioGui ) == true ) then             
                guiSetVisible ( RadioGui, false ) 
                showCursor ( false ) 
                guiSetInputEnabled ( false ) 
        else               
                guiSetVisible ( RadioGui, true ) 
                showCursor ( true ) 
                guiSetInputEnabled ( true ) 
        end 
end 
  
RadioGui = guiCreateWindow ( 0.75, 0.65, 0.25, 0.35, "ASDF - Radio Gui", true ) 
guiSetAlpha ( RadioGui, 0.9 ) 
guiSetVisible ( RadioGui, false ) 
RadioCloseButton = guiCreateButton ( 0.0, 0.85, 1.0, 0.25, "Close", true, RadioGui ) 
StationsGridList = guiCreateGridList ( 0.0, 0.1, 1.0, 0.70, true, RadioGui ) 
StationsList = guiGridListAddColumn( StationsGridList, "Stations List", 0.9 ) 
addCommandHandler ( "radio", CreateRadioGui ) 
  
function CloseRadioGui ( ) 
    if ( source == RadioCloseButton ) then 
        guiSetVisible ( RadioGui, false ) 
        showCursor ( false ) 
        guiSetInputEnabled ( false ) 
    end 
end 
addEventHandler ( "onClientGUIClick", RadioCloseButton, CloseRadioGui ) 
  
addEventHandler( "onClientResourceStart", getRootElement( ), 
function () 
    for StationName, StationAdress in pairs ( sTations ) do 
        local row = guiGridListAddRow ( StationsGridList ) 
        guiGridListSetItemText ( StationsGridList, row, 1, StationName, false, false ) 
    end 
end 
) 
  
function StartRadio() 
    if source == StationsGridList then 
        local row, col = guiGridListGetSelectedItem ( StationsGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) 
                playSound( sTations[statioN] ) 
            end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement( ), StartRadio ) 
  
function StopRadio() 
    if source == StationsGridList then 
        local row, col = guiGridListGetSelectedItem ( StationsGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) 
                stopSound( sTations[statioN] ) 
            end 
    end 
end 
addEventHandler("onClientDoubleClick", getRootElement( ), StopRadio ) 

Link to comment
local sTations ={ 
    ["Power 181"] = "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription="; 
} 
  
function CreateRadioGui ( )         
        if ( guiGetVisible ( RadioGui ) == true ) then             
                guiSetVisible ( RadioGui, false ) 
                showCursor ( false ) 
                guiSetInputEnabled ( false ) 
        else               
                guiSetVisible ( RadioGui, true ) 
                showCursor ( true ) 
                guiSetInputEnabled ( true ) 
        end 
end 
  
RadioGui = guiCreateWindow ( 0.75, 0.65, 0.25, 0.35, "ASDF - Radio Gui", true ) 
guiSetAlpha ( RadioGui, 0.9 ) 
guiSetVisible ( RadioGui, false ) 
RadioCloseButton = guiCreateButton ( 0.0, 0.85, 1.0, 0.25, "Close", true, RadioGui ) 
StationsGridList = guiCreateGridList ( 0.0, 0.1, 1.0, 0.70, true, RadioGui ) 
StationsList = guiGridListAddColumn( StationsGridList, "Stations List", 0.9 ) 
addCommandHandler ( "radio", CreateRadioGui ) 
  
function CloseRadioGui ( ) 
    if ( source == RadioCloseButton ) then 
        guiSetVisible ( RadioGui, false ) 
        showCursor ( false ) 
        guiSetInputEnabled ( false ) 
    end 
end 
addEventHandler ( "onClientGUIClick", RadioCloseButton, CloseRadioGui ) 
  
addEventHandler( "onClientResourceStart", getRootElement( ), 
function () 
    for StationName, StationAdress in pairs ( sTations ) do 
        local row = guiGridListAddRow ( StationsGridList ) 
        guiGridListSetItemText ( StationsGridList, row, 1, StationName, false, false ) 
    end 
end 
) 
  
function StartRadio() 
    if source == StationsGridList then 
        local row, col = guiGridListGetSelectedItem ( StationsGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) 
                radio = playSound( sTations[statioN] ) 
            end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement( ), StartRadio ) 
  
function StopRadio() 
    if source == StationsGridList then 
        local row, col = guiGridListGetSelectedItem ( StationsGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) 
                stopSound( radio ) 
            end 
    end 
end 
addEventHandler("onClientDoubleClick", getRootElement( ), StopRadio ) 

Link to comment

It's not working but I have made that and I have a mistake in addEventHandler ( 2 argument )

local sTations ={ 
    ["Power 181"] = "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription="; 
} 
  
function CreateRadioGui ( )         
        if ( guiGetVisible ( RadioGui ) == true ) then             
                guiSetVisible ( RadioGui, false ) 
                showCursor ( false ) 
                guiSetInputEnabled ( false ) 
        else               
                guiSetVisible ( RadioGui, true ) 
                showCursor ( true ) 
                guiSetInputEnabled ( true ) 
        end 
end 
  
RadioGui = guiCreateWindow ( 0.75, 0.65, 0.25, 0.35, "ASDF - Radio Gui", true ) 
guiSetAlpha ( RadioGui, 0.9 ) 
guiSetVisible ( RadioGui, false ) 
RadioCloseButton = guiCreateButton ( 0.0, 0.85, 1.0, 0.25, "Close", true, RadioGui ) 
StationsGridList = guiCreateGridList ( 0.0, 0.1, 1.0, 0.70, true, RadioGui ) 
StationsList = guiGridListAddColumn( StationsGridList, "Stations List", 0.9 ) 
addCommandHandler ( "radio", CreateRadioGui ) 
  
function CloseRadioGui ( ) 
    if ( source == RadioCloseButton ) then 
        guiSetVisible ( RadioGui, false ) 
        showCursor ( false ) 
        guiSetInputEnabled ( false ) 
    end 
end 
addEventHandler ( "onClientGUIClick", RadioCloseButton, CloseRadioGui ) 
  
addEventHandler( "onClientResourceStart", getRootElement( ), 
function () 
    for StationName, StationAdress in pairs ( sTations ) do 
        local row = guiGridListAddRow ( StationsGridList ) 
        guiGridListSetItemText ( StationsGridList, row, 1, StationName, false, false ) 
    end 
end 
) 
  
function StartRadio() 
    if source == StationsGridList then 
        local row, col = guiGridListGetSelectedItem ( StationsGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) 
                local radioItem = guiGridListGetSelectedItem ( StationsGridList ) 
                    radio = playSound( sTations[statioN] ) 
            end 
        end 
    end 
addEventHandler("onClientGUIClick", radioItem, Start ) 
     
function StopRadio() 
    if source == StationsGridList then 
        local row, col = guiGridListGetSelectedItem ( StationsGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) 
                local radioItem = guiGridListGetSelectedItem ( StationsGridList ) 
                stopSound( radio ) 
            end 
    end 
end 
addEventHandler("onClientGUIDoubleClick", radioItem, StopRadio ) 

Link to comment

Noticed the reason.

You are using onClientGUIClick, and for stopping, DoubleClick. So whenever you use a click it reproduces again, and after the second click, first one stops, but there is another one enabled

My recommendation: create a GUI Button so you don't have these kind of problems.

If you set them both to GUIClick or DoubleClick, no sound will be heard. So, another posible way is the following

Remove EventHandler for stopping Radio

add in start radio function:

addEventHandler("onClientGUIDoubleClick", StationsGridList, StopRadio ) 
removeEventHandler("onClientGUIClick", StationsGridList, StartRadio ) 

add in Stop radio function:

removeEventHandler("onClientGUIDoubleClick", StationsGridList, StopRadio ) 
addEventHandler("onClientGUIClick", StationsGridList, StartRadio ) 

Link to comment

Okey I made it with buttons but when I double-clicked on Play then sound starts again ( double sound )

function StartRadio() 
    if source == RadioPlayButton then 
        local row, col = guiGridListGetSelectedItem ( StationsGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) 
                local radioItem = guiGridListGetSelectedItem ( StationsGridList ) 
                    radio = playSound( sTations[statioN] ) 
            end 
        end 
    end 
addEventHandler("onClientGUIClick", RadioPlayButton, StartRadio ) 
  
function StopRadio() 
    if source == RadioStopButton then 
        local row, col = guiGridListGetSelectedItem ( StationsGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) 
                local radioItem = guiGridListGetSelectedItem ( StationsGridList ) 
                stopSound( radio ) 
            end 
    end 
end 
addEventHandler("onClientGUIClick", RadioStopButton, StopRadio ) 

Link to comment
function StartRadio() 
    if source == StationsGridList then 
        local row, col = guiGridListGetSelectedItem ( StationsGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) 
                if isElement( radio ) then stopSound( radio ) end 
                    radio = playSound( sTations[statioN] ) 
            end 
            end 
        end 
addEventHandler("onClientGUIClick", StationsGridList, StartRadio ) 

Working, but I can't stop this sound, when I click on it second time then play it again..

Link to comment
function StartRadio() 
    if source == StationsGridList then 
        local row, col = guiGridListGetSelectedItem ( StationsGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( StationsGridList, row, 1 ) 
                if isElement( radio ) then destroyElement( radio ) end 
                    radio = playSound( sTations[statioN] ) 
            end 
            end 
        end 
addEventHandler("onClientGUIClick", StationsGridList, StartRadio ) 

Doesn't make a sound

Link to comment
function StartRadio() 
    if source == StationsGridList then 
        local row, col = guiGridListGetSelectedItem ( StationsGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( StationsGridList, row, col ) 
                if isElement( radio ) then radio = false else 
                    radio = playSound( sTations[statioN] ) 
            end 
            end 
        end 
        end 
addEventHandler("onClientGUIClick", StationsGridList, StartRadio ) 

Why it's not working? :C

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