Android Question Internet Radio Player

Lupos

Member
Good morning to all.
Several months ago i've found on this forum a simple internet radio player without the use of EXOplayer.
i've tried with exoplayer without results :-(

I don't remember the author (spanish language) apologize me for that.

It works fine and i've created a simple app that allows to play various internet radio simply calling the stream address by pressing a button.
Meanwhile, i've created a WINDOWS radio player too that works in the same way BUT i've added a function that allows to obtain title track and artist name in real time from metadata.
The question is:
If i post the part of the code about that written in VB...
Can someone help me to translate in b4a to add this function to the app?
i'm not able to do that.
i don't know if i can post the original b4a code because is not mine.
Thanks to all.
 

Lupos

Member
Many thanks for the answer. Sir.
I'm using MediaPlayerStream.
Maybe in a future a solution will appear.
Thanks again.
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
Getting those meta data depends on your streaming server.

I have 3 different radio apps on the playstore using Exoplayer and I get those information separately through another webpage provided by the server, which I check with okhttputils

Some have REST APIs you can query as well.

A workaround which works with most servers.

Add 7.html to your URL, like this
it should be able to give you Artist and title as plain text
 
Upvote 0

Lupos

Member
This is my VB code for metadata extraction (found on the net and modified by me).
Could be useful?

Public Sub Title(ByVal testo As String)
Dim server As String = AxWindowsMediaPlayer1.URL
Dim request As HttpWebRequest = Nothing
Dim _response As HttpWebResponse = Nothing
Dim metaInt As Integer = 0 ' blocksize of mp3 data
Dim count As Integer = 0 ' byte counter
Dim metadataLength As Integer = 0 ' length of metadata header
Dim metadataHeader As String = "" ' previous metadata header, to compare with new header and find next song
Dim buffer As Byte() = New Byte(511) {} ' receive buffer
Dim socketStream As Stream = Nothing ' input stream on the web request
Dim byteOut As Stream = Nothing ' output stream on the destination file
Dim subst As String
request = DirectCast(WebRequest.Create(server), HttpWebRequest) ' create web request
request.Headers.Clear() ' clear old request header and build own header to receive ICY-metadata
request.Headers.Add("Icy-MetaData", "1") 'request.Headers.Add("GET", serverPath + " HTTP/1.0");
request.UserAgent = "WinampMPEG/5.09" ' needed to receive metadata informations

Try ' execute request
_response = DirectCast(request.GetResponse(), HttpWebResponse)
Catch ex As Exception
TitleTextBox.Text = "NOT AVAILABLE"
Return
End Try
metaInt = Convert.ToInt32(_response.GetResponseHeader("icy-metaint")) ' read blocksize to find metadata header
Try
socketStream = _response.GetResponseStream() ' open stream on response
While True ' rip stream in an endless loop
Dim bufLen As Integer = socketStream.Read(buffer, 0, buffer.Length) ' read byteblock
If bufLen < 0 Then
Return
End If
For i As Integer = 0 To bufLen - 1 ' if there is a header, the 'headerLength' would be set to a value != 0. Then we save the header to a string
If metadataLength <> 0 Then
metadataHeader += Convert.ToChar(buffer(i))
metadataLength -= 1
If metadataLength = 0 Then
Exit While
End If
Else
If System.Math.Max(System.Threading.Interlocked.Increment(count), count - 1) < metaInt Then ' write mp3 data to file or extract metadata headerlength
If byteOut IsNot Nothing Then ' write bytes to filestream
byteOut.Write(buffer, i, 1) ' as long as we don't have a songtitle, we don't open a new file and don't write any bytes
If count Mod 100 = 0 Then
byteOut.Flush()
End If
End If
Else
metadataLength = Convert.ToInt32(buffer(i)) * 16 ' get headerlength from lengthbyte and multiply by 16 to get correct headerlength
count = 0
End If
End If
Next
End While
Dim numberString As String = String.Empty
Dim str2 As String = ""
Dim numberString2 As String = String.Empty
If metadataHeader.Contains("'") Then
numberString = metadataHeader.IndexOf("'")
numberString2 = metadataHeader.IndexOf(";")
subst = metadataHeader.Substring(numberString + 1, numberString2 - numberString - 2)
TitleTextBox.Text = subst
Else
TitleTextBox.Text = "NOT AVAILABLE"
End If

Catch ex As Exception
TitleTextBox.Text = "NOT AVAILABLE"
Finally
If byteOut IsNot Nothing Then
byteOut.Close()
End If
If socketStream IsNot Nothing Then
socketStream.Close()
End If

End Try
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TextBoxBr.Text = (_response.Headers("icy-br"))
TextBoxWeb.Text = (_response.Headers("icy-url"))
TextBoxGenre.Text = (_response.Headers("icy-genre"))
TextBoxName.Text = (_response.Headers("icy-name"))
End Sub
 
Upvote 0
Top