Hola,
os dejo este codigo para obtener un reproductor de audio, útil para escuchar radio-web, archivos de audio y vídeo, con muestra de eventuales Metadatos y de un simple Espectroscopio, basado en los recursos del sistema audio "GStreamer".
Por lo tanto, es necesario activar el componente "
gb.media".
Código:
Private TextArea1 As TextArea
Private DrawingArea1 As DrawingArea
Private ToggleButton1 As ToggleButton
Private mp As MediaPlayer
Private Meta As New Collection
Private ss As New String[]
Public Sub Form_Open()
Me.Resize(Screen.AvailableWidth * 0.33, Screen.AvailableHeight * 0.73)
With TextArea1 = New TextArea(Me)
.X = Me.W * 0.02
.Y = Me.H * 0.02
.W = Me.W * 0.96
.H = Me.H * 0.4
End With
With DrawingArea1 = New DrawingArea(Me)
.X = Me.W * 0.02
.Y = Me.H * 0.43
.W = Me.W * 0.96
.H = Me.H * 0.46
End With
With ToggleButton1 = New ToggleButton(Me) As "ToggleButton1"
.W = Me.W * 0.3
.X = (Me.W * 0.5) - (.W / 2)
.Y = Me.H * 0.9
.H = Me.H * 0.08
.Foreground = Color.Green
.Text = "Ejecuta"
End With
End
Public Sub ToggleButton1_Click()
If ToggleButton1.Value Then
Dim plugVis As MediaControl
Dim tipoPlug As String[] = ["goom", "monoscope", "spacescope",
"spectrascope", "synaescope", "wavescope"]
TextArea1.Clear
With mp = New MediaPlayer As "MediaPlayer1"
plugVis = New MediaControl(mp, tipoPlug[3])
.SetWindow(DrawingArea1)
' Escuchamos una radio-web....
.URL = "https://icy.unitedradio.it/VirginRock70.mp3"
' Si queremos ejecutar un archivo de audio o de vídeo tendremos que sustituir la línea anterior por esta:
' .URL = Media.URL("/ruta/del/archivo/audio/o/video")
.Play
.Video.Visualisation = plugVis
End With
ToggleButton1.Foreground = Color.Red
ToggleButton1.Text = "Stop"
Else
mp.Stop
mp.Close
ToggleButton1.Foreground = Color.Green
ToggleButton1.Text = "Ejecuta"
Endif
End
Public Sub MediaPlayer1_Tag(tagList As MediaTagList)
For Each tag As String In tagList.Tags
If Not Meta.Exist(tag) Then
Meta[tag] = tagList[tag]
ss.Push(tag)
ss.Push(tagList[tag])
Else
ss[ss.Find(tag) + 1] = tagList[tag]
Endif
Next
TextArea1.Clear
For c As Short = 0 To ss.Max Step 2
TextArea1.Text &= ss[c] & ": " & ss[c + 1] & gb.NewLine
Next
End
Public Sub MediaPlayer1_Position()
Me.Title = Str(Time(0, 0, 0, mp.Pos * 1000))
End
Public Sub MediaPlayer1_End()
ToggleButton1.Value = False
End