开发者

how to handle media button to stop a song?

开发者 https://www.devze.com 2023-02-07 18:30 出处:网络
Ihav开发者_运维技巧e one service in which I am playing a song. Now I want to stop the song when I press volumn up and down button.

I hav开发者_运维技巧e one service in which I am playing a song. Now I want to stop the song when I press volumn up and down button.

I used broadcast receiver also with the following code but it doesn't help me

 if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON))
 {
      player.stop();    
 }


Intent you handled 'll not be fired when you press volume buttons of device but remote buttons like earphone buttons. I think there is no intent action associated with device volume buttons if those are not implemented in framework or hardware level. Please have look at it:

An example of the handling of media button intents I think you can catch these key events in onKeyDown() in an activity.


Now I want to stop the song when i press volumn up and down button.

The "volumn up and down button" is not the media button. There is no broadcast Intent for the volume rocker, so your service will not be able to find out about such presses on its own. An activity can watch for volume button KeyEvents via onKeyDown().

0

精彩评论

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