Ability to use the ACTION_MEDIA_BUTTON intent to play/pause/next music

2,903 views
Skip to first unread message

velazcod

unread,
Sep 4, 2010, 1:39:25 AM9/4/10
to Tasker
Example:

long eventtime = SystemClock.uptimeMillis();

Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent downEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0);
downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
sendOrderedBroadcast(downIntent, null);

Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent upEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0);
upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
sendOrderedBroadcast(upIntent, null);


This will allow us to pause music players that support the
ACTION_MEDIA_BUTTON intent (default players, pandora, etc). This
intent basically "simulates" the buttons on some headsets.

This would be a great feature.

Pent

unread,
Sep 4, 2010, 5:11:58 AM9/4/10
to Tasker
Does that work ? Have you tested it ?

I had assumed it was a protected broadcast.

Pent

Pent

unread,
Sep 4, 2010, 9:36:08 AM9/4/10
to Tasker
Nevermind, seems to work for the pause example at least. Will try the
others.

Thanks for the tip!

Pent

Pent

unread,
Sep 4, 2010, 12:38:21 PM9/4/10
to Tasker
This one is in next version, I added it as a flag to the Android Media
Control option.

It's just called Media Control now.

I couldn't test it on a 3rd party player (I havn't got one).

Pent

Daniel Velazco

unread,
Sep 4, 2010, 5:24:53 PM9/4/10
to Tasker

Stefan Sarzio

unread,
Sep 6, 2010, 12:47:19 PM9/6/10
to Tasker
Works fine with BeyondPod, as far as I've tested.

Pent

unread,
Sep 6, 2010, 12:48:30 PM9/6/10
to Tasker
Thanks Stefan.

Pent
Reply all
Reply to author
Forward
0 new messages