Reputation: 1686
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 ?
Upvotes: 22
Views: 2092
Reputation: 61
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
Upvotes: 0
Reputation: 592
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);
Upvotes: 1