LEON NICHOLLS: Hi, my name is Leon Nicholls.
I'm a Developer Advocate for Google Cast.
I'm here to tell you about the Google Cast SDK for Android.
The Google Cast SDK supports Android, iOS,
and desktop Chrome platforms.
Apps developed for these platforms can all
interact with any Google Cast device, such as Chromecast.
The Google Cast sender application
refers to an app running on a mobile device or laptop,
and the receiver application refers to an HTML application
running on Chromecast or other Google Cast receiver devices.
The release of the Google Cast SDK
is the public API for developers of Cast applications.
From now on, developers are in control
of releasing the Cast apps by using the new Google Cast SDK
developer console.
The Google Cast SDK is now a part of Android's Google Play
services, and will be shared across all Cast apps.
Let's take a look at the typical life cycle of a Cast sender
app.
When the sender app is launched, Cast devices
need to be discovered on the local network.
Once the user selects a device, the sender app
will connect to that device and launch the receiver app.
The sender app then creates a message channel
to the receiver app to send and receive messages.
The user can also disconnect from that device.
The first step in supporting Cast in an app
is to add the Cast button.
There are three choices-- the MediaRouter ActionBar provider,
the MediaRouter button, or a custom button.
We recommend the provider since that's the easiest integration.
The Cast button has to be added to the menu for the ActionBar,
or to the activity layout resource file.
The advantage to create a MediaRouter selector, which
will fall to devices to discover only
Cast devices that can run your app.
The selector is attached to the Cast button
when the activity starts.
Here is an example of how easy it
is to add a Cast button to the ActionBar
[? compat ?] using the MediaRouter ActionBar provider
in your menu XML.
Other ways of integrating the Cast button
is documented by the MediaRouter support library.
The sender app also has to tell the MediaRouter to start
discovery of Cast devices by adding
a callback when the activity starts.
The app will be informed by the MediaRouter
when the user has selected a device from the Cast menu.
As a best practice, remove the callback
when discovery is no longer needed,
to conserve battery usage.
Here's an example of how to add a callback to the MediaRouter
to start device discovery.
The device the user has selected is
extracted from the callback data.
Now that the sender app knows which
Cast device the user has selected,
launching the receiver app involves a few steps.
The sender app needs to connect to Google Play Services using
the GoogleAPIClient Cast.
Then the app uses the Cast.CastAPI
Cast to launch the receiver app using the app ID obtained
from the Developer Console.
Once the receiver app has launched,
the sender can create a media message channel or a custom
message channel to the receiver.
The app has to handle various callbacks
about the application and the channel status.
Here's an example of how to launch the receiver
app once the sender app has connected to Google Play
services.
The result callback is invoked with the launch status
and the application metadata.
Note the same asynchronous callback model
is used throughout the life cycle of a Cast app.
To play media on the receiver, the sender app
has to create a MediaInfo instance
with the URL of the media stream.
The RemoteMediaPlayer Cast is then
used to load that media stream on the receiver.
The sender app then accepts commands such as play and pause
using the RemoteMediaPlayer.
The sender app has to handle callbacks about the media
status during playback.
Finally, let's take a look at an example
of how to create a MediaInfo instance for a video stream.
The video stream is loaded on the receiver using
the RemoteMediaPlayer instance.
The ResultCallback is invoked with the load command status.
You can get more details about the Google Cast SDK
at developers.google.com/cast.
It's also important to take a look at the Cast Design
Checklist, which has design implications for your app.
We've also opened source sample Cast apps
that you can use as a reference.
If you have any developer questions,
post those on Stack Overflow.
Join our Google Cast Developers Community on Google+.
Happy Casting.