22

I'm looking for a way to send global media action (Play/pause, Next, Previous) to the phone, much like it can take it froma bluetooth paired radio/speaker.

I have found the MediaController class (http://developer.android.com/reference/android/widget/MediaController.html) but it seem more to be to implement the receiver of those action and i'm looking for a sender.

However, I can't seam to find any reference to this anywhere in the android doc...

Anyone already stumble on this ?

Remy Grandin
  • 1,638
  • 1
  • 14
  • 34

3 Answers3

1

So if your activity is called MainActivity you can do:

//for play/pause toggle
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "togglepause");
MainActivity.this.sendBroadcast(i);

//for next
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "next");
MainActivity.this.sendBroadcast(i);

//for prev
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "previous");
MainActivity.this.sendBroadcast(i);

//to change volume
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, *value*, AudioManager.FLAG_SHOW_UI);
jrsall92
  • 572
  • 1
  • 5
  • 19
0

take a look on BroadCastReceiver with actions HEADSET_PLUG and MEDIA_BUTTON, also LINK

maybe that would help you

M.Baraka
  • 725
  • 1
  • 10
  • 24
0

You can easily send broadcast actions for media (and many other events) with ActivityManager via adb e.g. adb shell am broadcast -a android.intent.action.MEDIA_MOUNTED will mount your media. See many more here: https://developer.android.com/reference/android/content/Intent.html

Wills
  • 61
  • 4