Android Tutorial How to get track change data

Discussion in 'Tutorials & Examples' started by NeoTechni, Sep 7, 2014.

  1. NeoTechni

    NeoTechni Well-Known Member Licensed User

    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

    Code:
    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

    Code:
    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

    Code:
    Sub GetExtra(StartingIntent As Intent, Extra As String, Default As StringAs String
        
    If startingintent.HasExtra(extra) Then Return startingintent.GetExtra(extra) Else Return default
    End Sub
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice