Google TV

Media keys

Google TV keyboards have seven media-control keys that are mapped to KeyEvent constants. These are listed in Table 1. If your application plays music, displays video or or runs a slide show, you can handle these control keys in the android.view.View.onKeyDown() callback for the View that controls the media.

Note: The media-control keys for Android versions prior to 2.3 (Gingerbread) are not supported.

Table 1. Google TV Media Keys, KeyEvent Mappings, and Symbols
1The symbol usually associated with the key. Some keyboards may have two symbols on the same key; in this case, the scan code sent out by the key is controlled by a separate modifier key.
Action KeyEvent keycode constant Keyboard Symbol1
Start playback KeyEvent.KEYCODE_MEDIA_PLAY illustration of a play button
Pause playback KeyEvent.KEYCODE_MEDIA_PAUSE illustration of a pause button
Stop playback KeyEvent.KEYCODE_MEDIA_STOP illustration of a stop button
Next KeyEvent.KEYCODE_MEDIA_NEXT illustration of a next button
Fast-forward KeyEvent.KEYCODE_MEDIA_FAST_FORWARD illustration of a fast-forward button
Previous KeyEvent.KEYCODE_MEDIA_PREVIOUS illustration of a previous selection button
Rewind KeyEvent.KEYCODE_MEDIA_REWIND illustration of a rewind button

This code snippet demonstrates how to handle media key events:

@Override
/**
 * Overrides the callback method for a UI control handling a slideshow
 **/
public boolean onKeyDown(int keyCode, KeyEvent event) {

  /*
   * Chooses the action to take, based on the incoming keycode
   */
  switch (keyCode) {
    case KeyEvent.KEYCODE_PAUSE:
         
      Log.d("MediaPlayer", "Pausing the slideshow");

      if (slideshow.pause()) {
        showStatusToast(R.string.slideshow_paused);
      }

      return true;

    case KeyEvent.KEYCODE_MEDIA_PLAY:
         
      Log.d(TAG, "Resuming the slideshow");
         
      if (slideshow.resume()) {
        showStatusToast(R.string.slideshow_resumed);
      }

      return true;

    /*
     * Keycodes should always be passed upwards in the chain for handling.
     */
    default:
      return super.onKeyDown(keyCode, event);
  }
}

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.