An implementation of Session
for managing connections to a Cast receiver device. An instance of CastSession
is automatically created by the SessionManager
when the user selects a Cast device from the media route controller dialog. The current
active CastSession
can be accessed by
SessionManager.getCurrentCastSession().
| void |
addCastListener(Cast.Listener listener)
Adds the
Cast.Listener
for Cast events, such as change of the application status and change of device
volume.
|
| int |
getActiveInputState()
Returns the device's active-input state.
|
| Cast.ApplicationConnectionResult |
getApplicationConnectionResult()
Returns the
Cast.ApplicationConnectionResult, the result of launching or joining
the receiver application when starting or resuming this session.
|
| ApplicationMetadata |
getApplicationMetadata()
Returns the metadata for the currently running receiver application, or
null if the metadata is unavailable.
|
| String |
getApplicationStatus()
Returns the current receiver application status, if any.
|
| CastDevice |
getCastDevice()
Returns the
CastDevice
this CastSession
is casting to.
|
| RemoteMediaClient |
getRemoteMediaClient()
Returns the
RemoteMediaClient for remote media control.
|
| long |
getSessionRemainingTimeMs()
Returns the amount of time that this
CastSession
instance should still be considered live by the SDK.
|
| int |
getStandbyState()
Returns the device's standby state.
|
| double |
getVolume()
Returns the device's volume, in the range [0.0, 1.0].
|
| boolean |
isMute()
Returns the device's mute state.
|
| void |
removeCastListener(Cast.Listener listener)
Removes the
Cast.Listener.
|
| void |
removeMessageReceivedCallbacks(String namespace)
Removes the
Cast.MessageReceivedCallback from this session for a given
namespace.
|
| void |
requestStatus()
Requests the latest status from the device.
|
| PendingResult<Status> |
sendMessage(String namespace,
String
message)
Sends a message to the currently connected application.
|
| void |
setMessageReceivedCallbacks(String namespace,
Cast.MessageReceivedCallback callbacks)
Sets the new
Cast.MessageReceivedCallback listener on this session for a given
namespace.
|
| void |
setMute(boolean mute)
Mutes or unmutes the device's audio.
|
| void |
setVolume(double volume)
Sets the device volume.
|
| void |
end(boolean stopCasting)
Ends the
CastSession.
|
| void | |
| void | |
| void | |
| void |
Adds the Cast.Listener
for Cast events, such as change of the application status and change of device
volume.
| IllegalStateException | If this method is not called on the main thread. |
|---|
Returns the device's active-input state. The returned value is Cast.ACTIVE_INPUT_STATE_YES,
Cast.ACTIVE_INPUT_STATE_NO,
or Cast.ACTIVE_INPUT_STATE_UNKNOWN.
| IllegalStateException | If there is no active service connection. |
|---|---|
| IllegalStateException | If this method is not called on the main thread. |
Returns the Cast.ApplicationConnectionResult,
the result of launching or joining the receiver application when starting or resuming
this session. Returns null if the session is not launched or joined
yet.
| IllegalStateException | If this method is not called on the main thread. |
|---|
Returns the metadata for the currently running receiver application, or
null if the metadata is unavailable.
| IllegalStateException | If there is no active service connection. |
|---|---|
| IllegalStateException | If this method is not called on the main thread. |
Returns the current receiver application status, if any. Message text is localized to the Google Cast device's locale.
| IllegalStateException | If there is no active service connection. |
|---|---|
| IllegalStateException | If this method is not called on the main thread. |
Returns the CastDevice
this CastSession
is casting to.
| IllegalStateException | If this method is not called on the main thread. |
|---|
Returns the
RemoteMediaClient for remote media control.
| IllegalStateException | If this method is not called on the main thread. |
|---|
Returns the amount of time that this CastSession
instance should still be considered live by the SDK. This method should be called only
by the SDK.
| IllegalStateException | If this method is not called on the main thread. |
|---|
Returns the device's standby state. The returned value is Cast.STANDBY_STATE_UNKNOWN,
Cast.STANDBY_STATE_NO,
or Cast.STANDBY_STATE_YES.
| IllegalStateException | If there is no active service connection. |
|---|---|
| IllegalStateException | If this method is not called on the main thread. |
Returns the device's volume, in the range [0.0, 1.0].
| IllegalStateException | If there is no active service connection. |
|---|---|
| IllegalStateException | If this method is not called on the main thread. |
Returns the device's mute state.
| IllegalStateException | If there is no active service connection. |
|---|---|
| IllegalStateException | If this method is not called on the main thread. |
Removes the Cast.Listener.
| IllegalStateException | If this method is not called on the main thread. |
|---|
Removes the Cast.MessageReceivedCallback
from this session for a given namespace.
| namespace | The namespace of the Cast channel. Namespaces must begin with the prefix "
urn:x-cast:". |
|---|
| IOException | If an I/O error occurs while performing the request. |
|---|---|
| IllegalArgumentException | If namespace is null or empty. |
| IllegalStateException | If this method is not called on the main thread. |
Requests the latest status from the device.
| IllegalStateException | If there is no active service connection. |
|---|---|
| IllegalStateException | If this method is not called on the main thread. |
| IOException |
Sends a message to the currently connected application.
| namespace | The namespace for the message. Namespaces must begin with the prefix "
urn:x-cast:". |
|---|---|
| message | The message payload. |
PendingResult
which can be used to see whether the message has been enqueued to be sent to a Google
Cast device, or null if the session is not connected.| IllegalStateException | If this method is not called on the main thread. |
|---|
Sets the new Cast.MessageReceivedCallback
listener on this session for a given namespace. The new listener will replace an
existing listener for a given namespace. Messages received by the session
for the given namespace will be forwarded to this listener.
| namespace | The namespace of the Cast channel. Namespaces must begin with the prefix "
urn:x-cast:". |
|---|---|
| callbacks | The Cast.MessageReceivedCallback
to perform callbacks on. May not be null. |
| IOException | If an I/O error occurs while performing the request. |
|---|---|
| IllegalStateException | If there is no active service connection. |
| IllegalArgumentException | If namespace is null or empty, or if the
namespace doesn't start with the prefix
"urn:x-cast:". |
| IllegalStateException | If this method is not called on the main thread. |
Mutes or unmutes the device's audio.
| IOException | If an I/O error occurs while performing the request. |
|---|---|
| IllegalStateException | If there is no active service connection. |
| IllegalStateException | If this method is not called on the main thread. |
Sets the device volume. If volume is outside of the range [0.0, 1.0],
then the value will be clipped.
| IOException | If an I/O error occurs while performing the request. |
|---|---|
| IllegalStateException | If this method is not called on the main thread. |
Ends the CastSession.
This method is called only by the SDK.
| stopCasting | Should the receiver app be stopped when the current session ends. |
|---|
This method is called prior to
resume(Bundle). Subclass should override this method to do necessary setup.
The default implementation does nothing.
| routeInfoExtra | the extra field of the selected media route and it can be obtained by
MediaRouter.RouteInfo.getExtras() |
|---|
This method is called prior to
start(Bundle). Subclass should override this method to do necessary setup.
The default implementation does nothing.
| routeInfoExtra | the extra field of the selected media route and it can be obtained by
MediaRouter.RouteInfo.getExtras() |
|---|
Resumes the CastSession.
This method is called only by the SDK.
| routeInfoExtra | The extra field in the MediaRouter.RouteInfo. |
|---|
Starts the CastSession.
This method is called only by the SDK.
| routeInfoExtra | The extra field in the MediaRouter.RouteInfo. |
|---|