Using Media Button Broadcasts with Samsung's default media player

时光总嘲笑我的痴心妄想 提交于 2019-12-08 04:21:54

问题


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 support media buttons, and if so how to fix it?


回答1:


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...



来源:https://stackoverflow.com/questions/6921075/using-media-button-broadcasts-with-samsungs-default-media-player

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!