Jump to content

Question about making online radio gui


jingzhi

Recommended Posts

GUIEditor = { 
scrollbar = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        local screenW, screenH = guiGetScreenSize() 
        RadioSystem = guiCreateWindow((screenW - 525) / 2, (screenH - 385) / 2, 525, 385, "Radio System", false) 
        guiWindowSetSizable(RadioSystem, false) 
        RadioPlay = guiCreateButton(274, 145, 142, 69, "Play", false, RadioSystem) 
        RadioStop = guiCreateButton(274, 267, 142, 69, "Stop", false, RadioSystem) 
        RadioStationList = guiCreateGridList(81, 135, 174, 211, false, RadioSystem) 
        guiGridListAddColumn(RadioStationList, "Radio Stations", 0.9) 
        for i = 1, 2 do 
            guiGridListAddRow(RadioStationList) 
        end 
        radio1 = guiGridListSetItemText(RadioStationList, 0, 1, "Power 181 Hit (Billboard top 40)", false, false) 
        radio2 = guiGridListSetItemText(RadioStationList, 1, 1, "Vibration108(Pop Rock)", false, false) 
  
        GUIEditor.scrollbar[1] = guiCreateScrollBar(2, 192, 172, 19, true, false, RadioStationList) 
  
        RadioSystemtext = guiCreateLabel(78, 38, 399, 58, "Radio System", false, RadioSystem) 
        Closeradiowindow = guiCreateButton(225, 346, 75, 29, "Close", false, RadioSystem) 
        guiSetFont(RadioSystemtext, "sa-header") 
        guiSetFont(RadioPlay, "sa-header") 
        guiSetFont(RadioStop, "sa-header")       
        guiSetFont(Closeradiowindow, "clear-normal")     
        guiSetVisible(RadioSystem,false) 
        bindKey("m", "down", showradioGUI ) 
    end) 
  
      
local urlPower181 = "http://www.181.fm/stream/asx/181-power.asx" 
local urlVibration108 = "http://www.vibration108.ch/listen.pls" 
function radiostationchoice(button) 
    if (button == "left") then 
    if (source == radio1) then 
         outputChatBox("radio selected") 
           radiourl = urlPower181 
    elseif (source == radio2) then 
          outputChatBox("radio selected")    
    radiourl = urlVibration108 
    elseif (source == RadioPlay) then 
       playSound(radiourl) 
    elseif (source == RadioStop) then 
       stopSound(radiourl) 
    elseif (source == Closeradiowindow) then 
       guiSetVisible(RadioSystem,false)    
       showCursor(false) 
       end 
       end 
end 
  
addEventHandler("onClientGUIClick",resourceRoot,radiostationchoice) 
addEventHandler("onClientGUIClick",resourceRoot,radiostationchoice) 
addEventHandler("onClientGUIClick",resourceRoot,radiostationchoice) 
addEventHandler("onClientGUIClick",resourceRoot,radiostationchoice) 
addEventHandler("onClientGUIClick",resourceRoot,radiostationchoice) 
  
function showradioGUI() 
    guiSetVisible(RadioSystem,true) 
    showCursor(true)  
end 

Hi so I got this problem with my scirpt, I want to make a GUI with gridlist and buttons, when i choose one item in gridlist and then i press play it will play the radio stream i chose,but this is not working, please help :)

Link to comment
But, wiki syntax ( playSound )..

say ; " playSound

Client-only function

Creates a sound element and plays it immediately after creation for the local player.

 The only supported audio formats are MP3, WAV, OGG, RIFF, MOD, XM, IT, S3M and PLS(e.g. Webstream)"

asx format isn't available .

Asx was already working, it has no problem

Link to comment
Try to use a table like this :
local radio = { 
{radio url } , 
{radio url } , 
{radio url } , 
  
} 
  
  
for i , v in pairs (radio) do  
local row = guiGridListAddRow(RadioStationList) 
guiGridListSetItemText(RadioStationList, row, 1, v[1], false, false) 
end 

Hey but if i do it this way will it show the text in gridlist?

Link to comment
Then issue could be with GUI ofcourse, can you tell me what exactly you are trying to do?

I am trying to make a gui for radio, if i choose a radio station from the gridlist and then i press play, it should play the online radio i chose in the gridlist, when i press stop it should stop :)

Link to comment

You could make a table like this;

local radioChannels = { 
    [1] = {"www.url.com/listen.pls", "Radio 108 FM"} 
}; 
  
outputChatBox(tostring(radioChannels[1][1])) -- Outputs "www.url.com/listen.pls" 
outputChatBox(tostring(radioChannels[1][2])) -- Outputs "Radio 108 FM" 

I am trying to make a gui for radio, if i choose a radio station from the gridlist and then i press play, it should play the online radio i chose in the gridlist, when i press stop it should stop :)

You could do something like this;

local currentSong = nil; 
local isSongPaused = false; 
  
-- Code and shizzle 
currentSong = playSound("www.example.com/listen.pls"); 
  
-- More code 
function muteSong_Handler() 
    if(getElementType(currentSong) == "sound") then 
        setSoundPaused(currentSong, not isSongPaused); 
        isSongPaused = (not isSongPaused); 
    else 
        outputChatBox("No radio is currently being streamed!") 
    end 
end 
  

Link to comment

I made whole new working one, and fixed some flaws from your current code:

function toggleGUI() 
    guiSetVisible(RadioSystem, not guiGetVisible(RadioSystem)) 
    showCursor(not isCursorShowing()) 
end 
  
local screenW, screenH = guiGetScreenSize() 
RadioSystem = guiCreateWindow((screenW - 525) / 2, (screenH - 385) / 2, 525, 385, "Radio System", false) 
guiWindowSetSizable(RadioSystem, false) 
RadioPlay = guiCreateButton(274, 145, 142, 69, "Play", false, RadioSystem) 
RadioStop = guiCreateButton(274, 267, 142, 69, "Stop", false, RadioSystem) 
RadioStationList = guiCreateGridList(81, 135, 174, 211, false, RadioSystem) 
    guiGridListAddColumn(RadioStationList, "Radio Stations", 1) 
RadioSystemtext = guiCreateLabel(78, 38, 399, 58, "Radio System", false, RadioSystem) 
Closeradiowindow = guiCreateButton(225, 346, 75, 29, "Close", false, RadioSystem) 
    guiSetFont(RadioSystemtext, "sa-header") 
    guiSetFont(RadioPlay, "sa-header") 
    guiSetFont(RadioStop, "sa-header")       
    guiSetFont(Closeradiowindow, "clear-normal")     
guiSetVisible(RadioSystem,false) 
bindKey("m", "down", toggleGUI) 
  
local radioChannels = { 
["Power 181"] = "http://www.181.fm/stream/asx/181-power.asx", 
["Vibration 108"] = "http://www.vibration108.ch/listen.pls" 
} 
  
for k, v in pairs(radioChannels) do 
    local row = guiGridListAddRow(RadioStationList) 
    guiGridListSetItemText(RadioStationList, row, 1, k, false, false) 
end 
  
local isPlaying = false 
local currentRadio 
  
function playRadio() 
    local r, c = guiGridListGetSelectedItem(RadioStationList) 
    if (r == -1) then outputChatBox("Please select a station name to play from Radio Stations gridlist.", 200, 0, 0) return end 
    local name = guiGridListGetItemText(RadioStationList, r, c) 
    for k, v in pairs(radioChannels) do 
        if k == name then 
            currentRadio = playSound(v) 
            isPlaying = true 
            playingURL = v 
            outputChatBox("Successfully started Radio: "..name, 0, 200, 0) 
            return 
        end 
    end 
end 
addEventHandler("onClientGUIClick", RadioPlay, playRadio, false) 
  
function stopRadio() 
    if (not isPlaying) then outputChatBox("No radio station is currently playing.", 200, 0, 0) return end 
    stopSound(currentRadio) 
    isPlaying = false 
    outputChatBox("Successfully stopped radio!", 0, 200, 0) 
end 
addEventHandler("onClientGUIClick", RadioStop, stopRadio, false) 
  
function closeGUI() 
    toggleGUI() 
end 
addEventHandler("onClientGUIClick", Closeradiowindow, closeGUI, false) 

Now you may add infinite Radio URLs in the table above, with this format:

["Radio Name"] = "http://radio.url/play.asx", 

Link to comment
You could make a table like this;
local radioChannels = { 
    [1] = {"www.url.com/listen.pls", "Radio 108 FM"} 
}; 
  
outputChatBox(tostring(radioChannels[1][1])) -- Outputs "www.url.com/listen.pls" 
outputChatBox(tostring(radioChannels[1][2])) -- Outputs "Radio 108 FM" 

I am trying to make a gui for radio, if i choose a radio station from the gridlist and then i press play, it should play the online radio i chose in the gridlist, when i press stop it should stop

You could do something like this;

local currentSong = nil; 
local isSongPaused = false; 
  
-- Code and shizzle 
currentSong = playSound("www.example.com/listen.pls"); 
  
-- More code 
function muteSong_Handler() 
    if(getElementType(currentSong) == "sound") then 
        setSoundPaused(currentSong, not isSongPaused); 
        isSongPaused = (not isSongPaused); 
    else 
        outputChatBox("No radio is currently being streamed!") 
    end 
end 
  

Thank you but i want a GUI panel for this :|

Link to comment
I made whole new working one, and fixed some flaws from your current code:
function toggleGUI() 
    guiSetVisible(RadioSystem, not guiGetVisible(RadioSystem)) 
    showCursor(not isCursorShowing()) 
end 
  
local screenW, screenH = guiGetScreenSize() 
RadioSystem = guiCreateWindow((screenW - 525) / 2, (screenH - 385) / 2, 525, 385, "Radio System", false) 
guiWindowSetSizable(RadioSystem, false) 
RadioPlay = guiCreateButton(274, 145, 142, 69, "Play", false, RadioSystem) 
RadioStop = guiCreateButton(274, 267, 142, 69, "Stop", false, RadioSystem) 
RadioStationList = guiCreateGridList(81, 135, 174, 211, false, RadioSystem) 
    guiGridListAddColumn(RadioStationList, "Radio Stations", 1) 
RadioSystemtext = guiCreateLabel(78, 38, 399, 58, "Radio System", false, RadioSystem) 
Closeradiowindow = guiCreateButton(225, 346, 75, 29, "Close", false, RadioSystem) 
    guiSetFont(RadioSystemtext, "sa-header") 
    guiSetFont(RadioPlay, "sa-header") 
    guiSetFont(RadioStop, "sa-header")       
    guiSetFont(Closeradiowindow, "clear-normal")     
guiSetVisible(RadioSystem,false) 
bindKey("m", "down", toggleGUI) 
  
local radioChannels = { 
["Power 181"] = "http://www.181.fm/stream/asx/181-power.asx", 
["Vibration 108"] = "http://www.vibration108.ch/listen.pls" 
} 
  
for k, v in pairs(radioChannels) do 
    local row = guiGridListAddRow(RadioStationList) 
    guiGridListSetItemText(RadioStationList, row, 1, k, false, false) 
end 
  
local isPlaying = false 
local currentRadio 
  
function playRadio() 
    local r, c = guiGridListGetSelectedItem(RadioStationList) 
    if (r == -1) then outputChatBox("Please select a station name to play from Radio Stations gridlist.", 200, 0, 0) return end 
    local name = guiGridListGetItemText(RadioStationList, r, c) 
    for k, v in pairs(radioChannels) do 
        if k == name then 
            currentRadio = playSound(v) 
            isPlaying = true 
            playingURL = v 
            outputChatBox("Successfully started Radio: "..name, 0, 200, 0) 
            return 
        end 
    end 
end 
addEventHandler("onClientGUIClick", RadioPlay, playRadio, false) 
  
function stopRadio() 
    if (not isPlaying) then outputChatBox("No radio station is currently playing.", 200, 0, 0) return end 
    stopSound(currentRadio) 
    isPlaying = false 
    outputChatBox("Successfully stopped radio!", 0, 200, 0) 
end 
addEventHandler("onClientGUIClick", RadioStop, stopRadio, false) 
  
function closeGUI() 
    toggleGUI() 
end 
addEventHandler("onClientGUIClick", Closeradiowindow, closeGUI, false) 

Now you may add infinite Radio URLs in the table above, with this format:

["Radio Name"] = "http://radio.url/play.asx", 

Again ryan, its you, thank you very very much :D

Link to comment
You can still use the code I provided you with a GUI... I simply provided you with an example of how you could set up a multi-dimensional array to simplify the addition of more radio stations.

How you want to make the GUI is up to you :P

ohhh i thought you were a different guy, now i realize :) ,i have checked your gui, they were really nice, but way too complex for me :D

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