RemoteMediaPlayer | Android Developers

Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

Language
close

- - About
  - Wear
  - TV
  - Auto
- - Get Started
  - Devices
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
  - Google Services
  - Samples
- - Google Play
  - Essentials
  - Get Users
  - Engage & Retain
  - Monetize
  - Tools & Reference
  - Developer Stories

## Results

Loading...
Summary: Nested Classes | Constants | Ctors | Methods | Inherited Methods | [Expand All]
public class

# RemoteMediaPlayer

extends Object
implements Cast.MessageReceivedCallback

java.lang.Object
↳ | com.google.android.gms.cast.RemoteMediaPlayer

## Class Overview

Class for controlling a media player application running on a receiver.

Some operations, like loading of media or adjusting volume, can be tracked. The corresponding methods return a `PendingResult` for this purpose.

## Summary

Nested Classes
interface | RemoteMediaPlayer.MediaChannelResult | Result of a media command.
interface | RemoteMediaPlayer.OnMetadataUpdatedListener | The listener interface for tracking metadata changes.
interface | RemoteMediaPlayer.OnStatusUpdatedListener | The listener interface for tracking player status changes.

Constants
int | RESUME_STATE_PAUSE | A resume state indicating that the player should be paused, regardless of its current state.
int | RESUME_STATE_PLAY | A resume state indicating that the player should be playing, regardless of its current state.
int | RESUME_STATE_UNCHANGED | A resume state indicating that the player state should be left unchanged.
int | STATUS_CANCELED | A status indicating that a request was canceled.
int | STATUS_FAILED | A status indicating that a request failed.
int | STATUS_REPLACED | A status indicating that the request's progress is no longer being tracked because another request of the same type has been made before the first request completed.
int | STATUS_SUCCEEDED | A status indicating that a request completed successfully.
int | STATUS_TIMED_OUT | A status indicating that a request has timed out.

Public Constructors
| RemoteMediaPlayer()

Public Methods
long | getApproximateStreamPosition() Returns the approximate stream position as calculated from the last received stream information and the elapsed wall-time since that update.
MediaInfo | getMediaInfo() Returns the current media information, if any.
MediaStatus | getMediaStatus() Returns the current media status, if any.
String | getNamespace() Returns the media control namespace.
long | getStreamDuration() Convenience method for getting the stream duration.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | load(GoogleApiClient apiClient, MediaInfo mediaInfo, boolean autoplay) Loads and optionally starts playback of a new media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | load(GoogleApiClient apiClient, MediaInfo mediaInfo) Loads and automatically starts playback of a new media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | load(GoogleApiClient apiClient, MediaInfo mediaInfo, boolean autoplay, long playPosition) Loads and optionally starts playback of a new media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | load(GoogleApiClient apiClient, MediaInfo mediaInfo, boolean autoplay, long playPosition, JSONObject customData) Loads and optionally starts playback of a new media item.
void | onMessageReceived(CastDevice castDevice, String namespace, String message) Called when a message is received from a given `CastDevice`.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | pause(GoogleApiClient apiClient) Pauses playback of the current media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | pause(GoogleApiClient apiClient, JSONObject customData) Pauses playback of the current media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | play(GoogleApiClient apiClient, JSONObject customData) Begins (or resumes) playback of the current media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | play(GoogleApiClient apiClient) Begins (or resumes) playback of the current media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | requestStatus(GoogleApiClient apiClient) Requests updated media status information from the receiver.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | seek(GoogleApiClient apiClient, long position) Seeks to a new position within the current media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | seek(GoogleApiClient apiClient, long position, int resumeState, JSONObject customData) Seeks to a new position within the current media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | seek(GoogleApiClient apiClient, long position, int resumeState) Seeks to a new position within the current media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | setActiveMediaTracks(GoogleApiClient apiClient, long[] trackIds) Sets the active media tracks.
void | setOnMetadataUpdatedListener(RemoteMediaPlayer.OnMetadataUpdatedListener listener) Sets the `RemoteMediaPlayer.OnMetadataUpdatedListener` to get metadata updates.
void | setOnStatusUpdatedListener(RemoteMediaPlayer.OnStatusUpdatedListener listener) Sets the `RemoteMediaPlayer.OnStatusUpdatedListener` to get status updates.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | setStreamMute(GoogleApiClient apiClient, boolean muteState, JSONObject customData) Toggles the stream muting.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | setStreamMute(GoogleApiClient apiClient, boolean muteState) Toggles the stream muting.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | setStreamVolume(GoogleApiClient apiClient, double volume, JSONObject customData) Sets the stream volume.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | setStreamVolume(GoogleApiClient apiClient, double volume) Sets the stream volume of the current media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | setTextTrackStyle(GoogleApiClient apiClient, TextTrackStyle trackStyle) Sets the text track style.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | stop(GoogleApiClient apiClient) Stops playback of the current media item.
PendingResult<RemoteMediaPlayer.MediaChannelResult> | stop(GoogleApiClient apiClient, JSONObject customData) Stops playback of the current media item.

[Expand] Inherited Methods
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
From interface com.google.android.gms.cast.Cast.MessageReceivedCallback
abstract void | onMessageReceived(CastDevice castDevice, String namespace, String message) Called when a message is received from a given `CastDevice`.

## Constants

#### public static final int RESUME_STATE_PAUSE

A resume state indicating that the player should be paused, regardless of its current state.

Constant Value: 2 (0x00000002)

#### public static final int RESUME_STATE_PLAY

A resume state indicating that the player should be playing, regardless of its current state.

Constant Value: 1 (0x00000001)

#### public static final int RESUME_STATE_UNCHANGED

A resume state indicating that the player state should be left unchanged.

Constant Value: 0 (0x00000000)

#### public static final int STATUS_CANCELED

A status indicating that a request was canceled.

Constant Value: 2 (0x00000002)

#### public static final int STATUS_FAILED

A status indicating that a request failed.

Constant Value: 1 (0x00000001)

#### public static final int STATUS_REPLACED

A status indicating that the request's progress is no longer being tracked because another request of the same type has been made before the first request completed. This applies to requests such as volume change, where a new request invalidates the results of a previous one.

Constant Value: 4 (0x00000004)

#### public static final int STATUS_SUCCEEDED

A status indicating that a request completed successfully.

Constant Value: 0 (0x00000000)

#### public static final int STATUS_TIMED_OUT

A status indicating that a request has timed out.

Constant Value: 3 (0x00000003)

## Public Constructors

#### public RemoteMediaPlayer ()

## Public Methods

#### public long getApproximateStreamPosition ()

Returns the approximate stream position as calculated from the last received stream information and the elapsed wall-time since that update.

##### Returns

- The approximate stream position, in milliseconds.

#### public MediaInfo getMediaInfo ()

Returns the current media information, if any.

#### public MediaStatus getMediaStatus ()

Returns the current media status, if any.

#### public String getNamespace ()

Returns the media control namespace.

#### public long getStreamDuration ()

Convenience method for getting the stream duration.

##### Returns

- The stream duration, in milliseconds.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> load (GoogleApiClient apiClient, MediaInfo mediaInfo, boolean autoplay)

Loads and optionally starts playback of a new media item.

##### Parameters

apiClient | The API client with which to perform the operation.
mediaInfo | An object describing the media item to load.
autoplay | Whether playback should start immediately.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> load (GoogleApiClient apiClient, MediaInfo mediaInfo)

Loads and automatically starts playback of a new media item.

##### Parameters

apiClient | The API client with which to perform the operation.
mediaInfo | An object describing the media item to load.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> load (GoogleApiClient apiClient, MediaInfo mediaInfo, boolean autoplay, long playPosition)

Loads and optionally starts playback of a new media item. The media item starts playback at `playPosition`.

##### Parameters

apiClient | The API client with which to perform the operation.
mediaInfo | An object describing the media item to load.
autoplay | Whether playback should start immediately.
playPosition | The initial playback position, in milliseconds from the beginning of the stream.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> load (GoogleApiClient apiClient, MediaInfo mediaInfo, boolean autoplay, long playPosition, JSONObject customData)

Loads and optionally starts playback of a new media item. The media item starts playback at `playPosition`. This method optionally sends custom data as a `JSONObject` with the load request.

##### Parameters

apiClient | The API client with which to perform the operation.
mediaInfo | An object describing the media item to load.
autoplay | Whether playback should start immediately.
playPosition | The initial playback position, in milliseconds from the beginning of the stream.
customData | Custom application-specific data to pass along with the request.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public void onMessageReceived (CastDevice castDevice, String namespace, String message)

Called when a message is received from a given `CastDevice`.

##### Parameters

castDevice | The castDevice from whence the message originated.
namespace | The namespace of the received message.
message | The received payload for the message.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> pause (GoogleApiClient apiClient)

Pauses playback of the current media item.

##### Parameters

apiClient | The API client with which to perform the operation.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> pause (GoogleApiClient apiClient, JSONObject customData)

Pauses playback of the current media item.

##### Parameters

apiClient | The API client with which to perform the operation.
customData | Custom application-specific data to pass along with the request.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> play (GoogleApiClient apiClient, JSONObject customData)

Begins (or resumes) playback of the current media item.

##### Parameters

apiClient | The API client with which to perform the operation.
customData | Custom application-specific data to pass along with the request.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> play (GoogleApiClient apiClient)

Begins (or resumes) playback of the current media item.

##### Parameters

apiClient | The API client with which to perform the operation.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> requestStatus (GoogleApiClient apiClient)

Requests updated media status information from the receiver. `RemoteMediaPlayer.OnStatusUpdatedListener` callback will be triggered, when the updated media status has been received. This will also update the internal state of the `RemoteMediaPlayer` object with the current state of the receiver, including the current session ID. This method should be called when joining an application that supports the media control namespace.

##### Parameters

apiClient | The API client with which to perform the operation.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> seek (GoogleApiClient apiClient, long position)

Seeks to a new position within the current media item.

##### Parameters

apiClient | The API client with which to perform the operation.
position | The new position, in milliseconds from the beginning of the stream.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> seek (GoogleApiClient apiClient, long position, int resumeState, JSONObject customData)

Seeks to a new position within the current media item.

##### Parameters

apiClient | The API client with which to perform the operation.
position | The new position, in milliseconds from the beginning of the stream.
resumeState | The action to take after the seek operation has finished.
customData | Custom application-specific data to pass along with the request.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> seek (GoogleApiClient apiClient, long position, int resumeState)

Seeks to a new position within the current media item.

##### Parameters

apiClient | The API client with which to perform the operation.
position | The new position, in milliseconds from the beginning of the stream.
resumeState | The action to take after the seek operation has finished.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> setActiveMediaTracks (GoogleApiClient apiClient, long[] trackIds)

Sets the active media tracks.

##### Parameters

apiClient | The API client with which to perform the operation.
trackIds | The media track IDs.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public void setOnMetadataUpdatedListener (RemoteMediaPlayer.OnMetadataUpdatedListener listener)

Sets the `RemoteMediaPlayer.OnMetadataUpdatedListener` to get metadata updates.

#### public void setOnStatusUpdatedListener (RemoteMediaPlayer.OnStatusUpdatedListener listener)

Sets the `RemoteMediaPlayer.OnStatusUpdatedListener` to get status updates.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> setStreamMute (GoogleApiClient apiClient, boolean muteState, JSONObject customData)

Toggles the stream muting.

##### Parameters

apiClient | The API client with which to perform the operation.
muteState | Whether the stream should be muted or unmuted.
customData | Custom application-specific data to pass along with the request.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> setStreamMute (GoogleApiClient apiClient, boolean muteState)

Toggles the stream muting.

##### Parameters

apiClient | The API client with which to perform the operation.
muteState | Whether the stream should be muted or unmuted.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> setStreamVolume (GoogleApiClient apiClient, double volume, JSONObject customData)

Sets the stream volume. If `volume` is outside of the range [0.0, 1.0], then the value will be clipped.

##### Parameters

apiClient | The API client with which to perform the operation.
volume | The new volume, in the range [0.0 - 1.0].
customData | Custom application-specific data to pass along with the request.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

##### Throws

IllegalArgumentException | If the volume is infinity or NaN.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> setStreamVolume (GoogleApiClient apiClient, double volume)

Sets the stream volume of the current media item. When the stream volume has been updated, `onStatusUpdated()` will be called.

##### Parameters

apiClient | The API client with which to perform the operation.
volume | The new volume, in the range [0.0 - 1.0].

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

##### Throws

IllegalArgumentException | If the volume is infinity or NaN.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> setTextTrackStyle (GoogleApiClient apiClient, TextTrackStyle trackStyle)

Sets the text track style.

##### Parameters

apiClient | The API client with which to perform the operation.
trackStyle | The track style.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> stop (GoogleApiClient apiClient)

Stops playback of the current media item.

##### Parameters

apiClient | The API client with which to perform the operation.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.

#### public PendingResult<RemoteMediaPlayer.MediaChannelResult> stop (GoogleApiClient apiClient, JSONObject customData)

Stops playback of the current media item.

##### Parameters

apiClient | The API client with which to perform the operation.
customData | Custom application-specific data to pass along with the request.

##### Returns

- A `PendingResult` which can be used to track the progress of the request.