A BroadcastReceiver
for receiving media button actions from the status bar notification, the lock screen, and the
cast dialog.
MediaIntentReceiver
can be subclassed to handle custom actions by overriding
onReceiveOtherAction(Context, String, Intent)
, or override the default behavior
when handling pre-defined actions. In that case, set the name of the subclass when building
CastMediaOptions
by calling
CastMediaOptions.Builder.setMediaIntentReceiverClassName(String)
, and declare the
subclass in your manifest.
// MyMediaIntentReceiver.java public class MyMediaIntentReceiver extends MediaIntentReceiver { @Override protected void onReceiveOtherAction(Context context, String action, Intent) { // Handle custom actions of the media notification. ... } }
// MyOptionsProvider.java public class MyOptionsProvider extends OptionsProvider { @Override public CastOptions getCastOptions(Context context) { ... CastMediaOptions mediaOptions = new CastMediaOptions.Builder() .setMediaIntentReceiverClassName(MyMediaIntentReceiver.class.getName()) // Set other media options. ... .build(); ... } }
Constant Summary
String | ACTION_DISCONNECT | The action for ending the current session and disconnecting from the receiver app. |
String | ACTION_FORWARD | The action for forwarding the current item. |
String | ACTION_REWIND | The action for rewinding the current item. |
String | ACTION_SKIP_NEXT | The action for skipping to the next item in the queue. |
String | ACTION_SKIP_PREV | The action for skipping to the previous item in the queue. |
String | ACTION_STOP_CASTING | The action for ending the current session and stopping the receiver app. |
String | ACTION_TOGGLE_PLAYBACK | The action for toggling remote media playback. |
String | EXTRA_SKIP_STEP_MS | The extra key for specifying how much the
currently playing item should be forwarded or rewinded to handle
ACTION_FORWARD and
ACTION_REWIND . |
Public Constructor Summary
Public Method Summary
void |
Protected Method Summary
void |
onReceiveActionForward(Session
currentSession, long forwardStepMs)
Called when
ACTION_FORWARD is received.
|
void |
onReceiveActionMediaButton(Session
currentSession, Intent
intent)
Called when
Intent.ACTION_MEDIA_BUTTON is received.
|
void |
onReceiveActionRewind(Session
currentSession, long rewindStepMs)
Called when
ACTION_REWIND is received.
|
void | |
void | |
void |
onReceiveActionTogglePlayback(Session
currentSession)
Called when
ACTION_TOGGLE_PLAYBACK is received.
|
void |
onReceiveOtherAction(String action,
Intent
intent)
This method is deprecated. Overrides
onReceiveOtherAction(Context, String, Intent) instead.
|
void |
onReceiveOtherAction(Context
context, String action,
Intent
intent)
Called when other type of actions are received.
|
Inherited Method Summary
Constants
public static final String ACTION_DISCONNECT
The action for ending the current session and disconnecting from the receiver app.
public static final String ACTION_FORWARD
The action for forwarding the current item. When building an Intent with this
action, use
EXTRA_SKIP_STEP_MS
to set the time to forward in milliseconds.
public static final String ACTION_REWIND
The action for rewinding the current item. When building an Intent with this action,
use
EXTRA_SKIP_STEP_MS
to set the time to rewind in milliseconds.
public static final String ACTION_SKIP_NEXT
The action for skipping to the next item in the queue.
public static final String ACTION_SKIP_PREV
The action for skipping to the previous item in the queue.
public static final String ACTION_STOP_CASTING
The action for ending the current session and stopping the receiver app.
public static final String ACTION_TOGGLE_PLAYBACK
The action for toggling remote media playback.
public static final String EXTRA_SKIP_STEP_MS
The extra key for specifying how much the currently playing item should be forwarded
or rewinded to handle
ACTION_FORWARD
and
ACTION_REWIND
.
Public Constructors
public MediaIntentReceiver ()
Public Methods
Protected Methods
protected void onReceiveActionForward (Session currentSession, long forwardStepMs)
Called when
ACTION_FORWARD
is received. The default implementation forwards the current
playing item by forwardStepMs
if currentSession
is a
CastSession
.
Subclasses can override this method to change the behavior or handle other type of
Session
.
Subclasses should call through to super to let the SDK handle the action if
currentSession
is a CastSession
Parameters
currentSession | The current Session . |
---|---|
forwardStepMs | Time to forward in milliseconds. |
protected void onReceiveActionMediaButton (Session currentSession, Intent intent)
Called when Intent.ACTION_MEDIA_BUTTON
is received. The default implementation toggles playback state if
currentSession
is a CastSession
.
Subclasses can override this method to change the behavior or handle other type of
Session
.
Subclasses should call through to super to let the SDK handle the action if
currentSession
is a CastSession
Parameters
currentSession | The current Session . |
---|---|
intent | The Intent of this action. |
protected void onReceiveActionRewind (Session currentSession, long rewindStepMs)
Called when
ACTION_REWIND
is received. The default implementation rewinds the current
playing item by rewindStepMs
if currentSession
is a
CastSession
.
Subclasses can override this method to change the behavior or handle other type of
Session
.
Subclasses should call through to super to let the SDK handle the action if
currentSession
is a CastSession
Parameters
currentSession | The current Session . |
---|---|
rewindStepMs | Time to forward in milliseconds. |
protected void onReceiveActionSkipNext (Session currentSession)
Called when
ACTION_SKIP_NEXT
is received. The default implementation plays the next item
in the queue if currentSession
is a CastSession
and there is a next item. Subclasses can override this method to change the behavior or
handle other type of Session
.
Subclasses should call through to super to let the SDK handle the action if
currentSession
is a CastSession
Parameters
currentSession | The current Session . |
---|
protected void onReceiveActionSkipPrev (Session currentSession)
Called when
ACTION_SKIP_PREV
is received. The default implementation plays the previous
item in the queue if currentSession
is a CastSession
and there is a previous item. Subclasses can override this method to change the
behavior or handle other type of Session
.
Subclasses should call through to super to let the SDK handle the action if
currentSession
is a CastSession
Parameters
currentSession | The current Session . |
---|
protected void onReceiveActionTogglePlayback (Session currentSession)
Called when
ACTION_TOGGLE_PLAYBACK
is received. The default implementation toggles
playback state if currentSession
is a CastSession
.
Subclasses can override this method to change the behavior or handle other type of
Session
.
Subclasses should call through to super to let the SDK handle the action if
currentSession
is a CastSession
Parameters
currentSession | The current Session . |
---|
protected void onReceiveOtherAction (String action, Intent intent)
This method is deprecated.
Overrides
onReceiveOtherAction(Context, String, Intent)
instead.