开发者

Using Media Button Broadcasts with Samsung's default media player

I built an app using Intent.ACTION_MEDIA_BUTTON to control the current media play, but a customer reported it wasn't working with their Samsung music player. Does anyone know if the Samsung media player doesn't su开发者_如何学Cpport media buttons, and if so how to fix it?


I don't have a solution for you, but I can confirm that the stock media player on my Samsung Galaxy S / Android 2.1 testing unit does not respond to either 'toggle play/pause' (KEYCODE_MEDIA_PLAY_PAUSE) or 'next track' (KEYCODE_MEDIA_NEXT), so it's a fair bet that it won't respond to others either.

If you use logcat to follow what happens when you use the stock headset to 'toggle play/pause' using the inline switch/mic, you can see it sending KEYCODE_HEADSETHOOK, which you can send in code and will at least 'toggle play/pause' on the stock media player.

But that's it. Bit rubbish, really. Good on ya, Samsung!

EDIT: After a bit more digging I got the following to work with the Samsung Media Player:

Intent musicIntent = new Intent();
musicIntent.setAction("com.sec.android.app.music.musicservicecommand.togglepause");
sendBroadcast(musicIntent);

and:

Intent musicIntent = new Intent();
musicIntent.setAction("com.sec.android.app.music.musicservicecommand.next");
sendBroadcast(musicIntent);

I would be very interested to know how generally applicable this is - seems a bit fragile to me...

And lastly, along the same lines I found (replace the musicIntent.setAction() line with):

musicIntent.setAction("com.android.music.musicservicecommand.next");
musicIntent.putExtra("command", "next"); // or "next" or "previous"

This did not work with the Samsung player, but might be of use to someone...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜