diff --git a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java index cce2ebfc28..84d5fea0c7 100644 --- a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java +++ b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java @@ -30,6 +30,7 @@ import android.support.v4.media.session.MediaControllerCompat; import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.PlaybackStateCompat; import android.util.Pair; +import android.view.KeyEvent; import androidx.annotation.LongDef; import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; @@ -500,6 +501,17 @@ public final class MediaSessionConnector { * Sets the {@link MediaButtonEventHandler}. Pass {@code null} if the media button event should be * handled by {@link MediaSessionCompat.Callback#onMediaButtonEvent(Intent)}. * + *

Please note that prior to API 21 MediaButton events are not delivered to the {@link + * MediaSessionCompat}. Instead they are delivered as key events (see 'Responding to media + * buttons'). In an {@link android.app.Activity Activity}, media button events arrive at the + * {@link android.app.Activity#dispatchKeyEvent(KeyEvent)} method. + * + *

If you are running the player in a foreground service (prior to API 21), you can create an + * intent filter and handle the {@code android.intent.action.MEDIA_BUTTON} action yourself. See + * Service handling ACTION_MEDIA_BUTTON for more information. + * * @param mediaButtonEventHandler The {@link MediaButtonEventHandler}, or null to let the event be * handled by {@link MediaSessionCompat.Callback#onMediaButtonEvent(Intent)}. */