Android Tutorial How to get track change data

ie: If you want to make a music control widget

First you need to add a broadcast listener to the manifest


Then add this code to your Service_Start sub

B4X:
If StartingIntent.HasExtra("track") Then
        MusicCommand =  GetExtra(StartingIntent, "command", "")
        MusicTrack = GetExtra(StartingIntent, "track", "UNKNOWN TRACK")
        MusicAlbum = GetExtra(StartingIntent, "album", "UNKNOWN ALBUM")
        MusicArtist = GetExtra(StartingIntent, "artist", "UNKNOWN ARTIST")
        Log("Track changed to: " & MusicTrack & " (" & MusicAlbum & " - " & MusicArtist & ")")'substitute with whatever code you want to handle the change
    End If

This to your Process_Globals

B4X:
Dim MusicArtist As String = "NO ARTIST", MusicAlbum As String = "NO ALBUM", MusicTrack As String = "NO TRACK", MusicCommand As String

And this anywhere in the service

B4X:
Sub GetExtra(StartingIntent As Intent, Extra As String, Default As String) As String
    If startingintent.HasExtra(extra) Then Return startingintent.GetExtra(extra) Else Return default
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…