AI-generated Key Takeaways
-
CastReceiverContext
is the entry point for the Cast TV SDK and provides a shared instance for receiver applications. -
It allows managing media playback through the
MediaManager
, handling communication with senders, and observing events. -
Developers can register listeners for messages from senders and callbacks for various events like sender connection changes.
-
The
start()
andstop()
methods signal the receiver app's readiness to handle Cast commands. -
Through this class, developers can access sender information, send messages to specific senders or broadcast to all, and retrieve receiver options.
The singleton class as the entry point of the Cast TV SDK.
Nested Class Summary
class | CastReceiverContext.EventCallback | Callback class for observing various events. | |
interface | CastReceiverContext.MessageReceivedListener | Listener for listening messages that come from the sender. |
Public Method Summary
static CastReceiverContext |
getInstance()
Returns the shared instance.
|
MediaManager |
getMediaManager()
Returns the
MediaManager .
|
CastReceiverOptions |
getReceiverOptions()
Returns the receiver options.
|
SenderInfo | |
Collection<SenderInfo> |
getSenders()
Returns all senders.
|
static void | |
void |
registerEventCallback(CastReceiverContext.EventCallback
callback)
Registers a
CastReceiverContext.EventCallback
|
void | |
void |
sendMessage(String namespace,
String
senderId, String message)
Sends a message to a specific sender.
|
void |
setMessageReceivedListener(String namespace,
CastReceiverContext.MessageReceivedListener listener)
Sets a listener for a given namespace.
|
void |
start()
Tells the Cast TV SDK that the receiver app has started and is ready to accept
commands.
|
void |
stop()
Tells the Cast TV SDK that the receiver app has stopped and won't accept
commands any more.
|
void |
unregisterEventCallback(CastReceiverContext.EventCallback
callback)
Unregisters a
CastReceiverContext.EventCallback
|
Inherited Method Summary
Public Methods
public static CastReceiverContext getInstance ()
Returns the shared instance. Returns null
if the instance hasn't been
initialized.
public MediaManager getMediaManager ()
Returns the MediaManager
.
public CastReceiverOptions getReceiverOptions ()
Returns the receiver options.
public SenderInfo getSender (String senderId)
Returns the SenderInfo
with the given senderId
. Returns null
if not found.
public Collection<SenderInfo> getSenders ()
Returns all senders.
public static void initInstance (Context context)
Initializes the shared instance.
public void registerEventCallback (CastReceiverContext.EventCallback callback)
Registers a
CastReceiverContext.EventCallback
public void removeMessageReceivedListener (String namespace)
Removes a listener for a given namespace.
public void sendMessage (String namespace, String senderId, String message)
Sends a message to a specific sender.
Parameters
namespace | the namespace. Note that a valid namespace has to be prefixed with the string 'urn:x-cast:' |
---|---|
senderId | the sender Id, or null for broadcast to all senders |
message | the message |
public void setMessageReceivedListener (String namespace, CastReceiverContext.MessageReceivedListener listener)
Sets a listener for a given namespace.
Will replace a listener for the namespace if there is one.
public void start ()
Tells the Cast TV SDK that the receiver app has started and is ready to accept commands.
The MediaCommandCallback
and
CastReceiverContext.MessageReceivedListener
will be invoked if new messages
arrive.
public void stop ()
Tells the Cast TV SDK that the receiver app has stopped and won't accept commands any more.
The MediaCommandCallback
and
CastReceiverContext.MessageReceivedListener
will no longer be invoked.
public void unregisterEventCallback (CastReceiverContext.EventCallback callback)
Unregisters a
CastReceiverContext.EventCallback