Code: Select all
@VERSION 11, 0
@REQUIRE "rapagui"
@DISPLAY {Hidden=True, Layers=True}
; Global variables
Local radio_urls = {
"http://stream3.polskieradio.pl:8904/",
"http://stream.357.pl:8000/357.mp3",
"http://stream.nowyswiat.pl:8000/nowyswiat.mp3"
}
Local current_station = 0
; RapaGUI interface definition
Local gui_def$ = [[
<application id="app">
<window title="Radio" notify="closerequest">
<vgroup>
<hgroup>
<button id="button_trojka" notify="pressed">Troika</button>
<button id="button_radio357" notify="pressed">Radio 357</button>
<button id="button_nowyswiat" notify="pressed">Nowy Świat</button>
</hgroup>
<hgroup>
<button id="button_stop" notify="pressed">Stop</button>
</hgroup>
<text id="current_station">Current station: None</text>
</vgroup>
</window>
</application>
]]
; Function to play a radio station
Function p_PlayStation(id)
; Stop any currently playing music
StopMusic()
current_station = id
SetAttribute("current_station", "contents", "Current station: " .. radio_urls[id])
; Attempt to play the selected radio stream
If Not PlayMusic(radio_urls[id])
SetAttribute("current_station", "contents", "Current station: Playback error")
DebugPrint("Error playing stream: " .. radio_urls[id])
Else
DebugPrint("Playing: " .. radio_urls[id])
EndIf
EndFunction
; Function to stop playback
Function p_Stop()
; Stop the currently playing music
StopMusic()
SetAttribute("current_station", "contents", "Current station: None")
EndFunction
; Function to handle RapaGUI events
Function p_RapaGUIEvent(msg)
Switch msg.Class
Case "Window":
If msg.Attribute = "CloseRequest"
End
EndIf
Case "Button":
Switch msg.ID
Case "button_trojka":
p_PlayStation(0)
Case "button_radio357":
p_PlayStation(1)
Case "button_nowyswiat":
p_PlayStation(2)
Case "button_stop":
p_Stop()
EndSwitch
EndSwitch
EndFunction
; Create GUI
moai.CreateApp(gui_def$)
; Install event handler
InstallEventHandler({RapaGUI = p_RapaGUIEvent})
; Main loop
Repeat
WaitEvent
Forever