Radio code

Post

Posted
Rating:
#1 (In Topic #1143)
Avatar
Guru
cogier is in the usergroup ‘Guru’
cogier is in the usergroup ‘GambOS Contributor’
I found some excellent code to play internet radio by vuott :!:  here and here. I thought I would make a few changes! (Press [F11] for full-screen mode).

<IMG src="https://www.cogier.com/gambas/VirginRock70.png"> </IMG>

Code (gambas)

  1. ' Gambas class file
  2.  
  3. '' Requires gb.media
  4.  
  5. Private TextArea1 As TextArea
  6. Private DrawingArea1 As DrawingArea
  7. Private ToggleButton1 As ToggleButton
  8. Private ButtonDisplay As Button
  9. Private Splitter1 As Splitter
  10. Private mp As MediaPlayer
  11. Private iDisplay As Integer
  12. Private tipoPlug As String[] = ["goom", "monoscope", "spacescope", "spectrascope", "synaescope", "wavescope"]
  13. Private plugVis As MediaControl
  14.  
  15. Public Sub Form_Open()
  16.  
  17.   Dim iSH As Integer = Screen.AvailableHeight
  18.   Dim iSW As Integer = Screen.AvailableWidth
  19.  
  20.   If Not Component.IsLoaded("gb.settings") Then Component.Load("gb.settings")
  21.  
  22.   iDisplay = Settings["display", 0]
  23.  
  24.   With Me
  25.     .Arrangement = Arrange.Vertical
  26.     .Padding = 5
  27.     .H = iSH * 0.73
  28.     .W = iSW * 0.6
  29.  
  30.   DrawingArea1 = New DrawingArea(Me)
  31.   DrawingArea1.Expand = True
  32.   DrawingArea1.Tooltip = "Press F11 to toggle fullscreen"
  33.  
  34.   With HBox1 = New HBox(Me)
  35.     .Padding = 5
  36.     .H = iSH * 0.05
  37.     .Invert = True
  38.  
  39.   With ToggleButton1 = New ToggleButton(HBox1) As "ToggleButton1"
  40.     .W = iSW * 0.07
  41.     .Foreground = Color.Green
  42.     .Font.Size = 12
  43.     .Font.Bold = True
  44.     .Text = "&Start"
  45.  
  46.   With ButtonDisplay = New Button(HBox1) As "ButtonDisplay"
  47.     .W = iSW * 0.07
  48.     .Foreground = Color.Green
  49.     .Font.Size = 12
  50.     .Font.Bold = True
  51.     .Text = "&Display"
  52.  
  53.   ToggleButton1_Click(True)
  54.  
  55.  
  56. Public Sub ButtonDisplay_Click()
  57.  
  58.   Inc iDisplay
  59.   If iDisplay > 5 Then iDisplay = 0
  60.   ToggleButton1_Click
  61.   ToggleButton1_Click(True)
  62.   Settings["display"] = iDisplay
  63.   Settings.Save
  64.  
  65.  
  66. Public Sub ToggleButton1_Click(Optional bSkip As Boolean)
  67.  
  68.   If ToggleButton1.Value Or bSkip = True Then
  69.     ToggleButton1.Value = True  
  70.     With mp = New MediaPlayer As "MediaPlayer1"
  71.       plugVis = New MediaControl(mp, tipoPlug[iDisplay])
  72.       .Video.Output = New MediaControl(mp, "ximagesink")
  73.       .SetWindow(DrawingArea1)
  74.       .URL = "https://icy.unitedradio.it/VirginRock70.mp3"
  75.       .Play
  76.       .Video.Visualisation = plugVis
  77.     End With
  78.     ToggleButton1.Foreground = Color.Red
  79.     ToggleButton1.Text = "&Stop"
  80.   Else
  81.     mp.Stop
  82.     mp.Close
  83.     ToggleButton1.Foreground = Color.Green
  84.     ToggleButton1.Text = "&Start"
  85.  
  86.  
  87. Public Sub MediaPlayer1_Tag(tagList As MediaTagList)
  88.  
  89.   Dim sSplit As String[]
  90.  
  91.   For Each tag As String In tagList.Tags
  92.     If Not Meta.Exist(tag) Then
  93.       Meta[tag] = tagList[tag]
  94.       ss.Push(tag)
  95.       ss.Push(tagList[tag])
  96.     Else
  97.       ss[ss.Find(tag) + 1] = tagList[tag]
  98.     Endif
  99.   Next
  100.  
  101.   If ss.Find("title") > 1 Then
  102.     sSplit = Split(ss[ss.Find("title") + 1], "~", "", True)
  103.     Me.Title = sSplit[0] & ", " & sSplit[1] & " (" & sSplit[2] & ")"
  104.   End If
  105.  
  106.  
  107. Public Sub Form_KeyRelease()
  108.  
  109.   If Key.code = Key["F11"] Then
  110.     If Me.Border = True Then
  111.       Settings.Save
  112.       Me.border = False
  113.       Me.Maximized = True
  114.       Me.padding = 0
  115.       HBox1.Visible = False
  116.     Else
  117.       Me.border = True
  118.       Me.Maximized = False
  119.       HBox1.Visible = True
  120.       Me.padding = 5
  121.       Me.Refresh
  122.       Wait
  123.     Endif
  124.  
  125.  
  126. Public Sub MediaPlayer1_End()
  127.  
  128.   ToggleButton1.Value = False
  129.  
  130.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.