Search code examples
androidandroid-mediaplayermedia-playermediacontroller

How to send media action button to current player?


Is there any way to send a media action button to current media player (like Walkman or google play music) to play and pause or next and previous song.

actually i want to create a simple remote control


Solution

  • i find my answer here

    if (mAudioManager == null) mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
    
    KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
    mAudioManager.dispatchMediaKeyEvent(event);