widget and mediabrowser

stefanoa

Active Member
Licensed User
Longtime User
i've a music player app using MediaBrowser... YouMediaPlayer
i need to create a widget with which to control some functions such as play / pause / stop / etc.
if i play a song from my app and then minimize the app, the song continue playing..
how can i STOP or pause the song from widget?the problem is that they are 2 separate apps (widget and app) and cannot interact
some ideas?
 

thedesolatesoul

Expert
Licensed User
Longtime User
Adapting warwounds example here: http://www.b4x.com/forum/basic4andr...-any-way-execute-command-inside-variable.html

When clicking on the widget to send an intent:
B4X:
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_MAIN, "")
Intent1.SetComponent("your.application.package.name.here/.youractivity")
Intent1.PutExtra("Var1", Var1)
Intent1.PutExtra("Var2", Var2)
StartActivity(Intent1)
so in Var1 you can put State = Playing, Paused etc
OR​
If setcomponent does not work then you can try making an action like:
B4X:
AddActivityText(youractivity,
<intent-filter>
<action android:name="com.packagename.myaction" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>)

To receive the intent in your main application:
B4X:
Sub Activity_Resume

    Dim Intent1 As Intent
    Intent1=Activity.GetStartingIntent
    If Intent1.HasExtra("Var1") AND Intent1.HasExtra("Var2") Then
        Dim Var1 As String=intent1.GetExtra("Var1")
        Dim Var2 As String=intent1.GetExtra("Var2")
    Else
        '    handle the activity being started with an Intent that doesn't contain the required values
    End If
    
End Sub
 
Upvote 0
Top