KRISTAN UCCELLO: Hi.
My name's Krispy.
I'm a Developer Advocate on the Cast Developer Relations team.
In this DevBytes video, I will discuss
Google Cast receivers and how development
works with Cast receiver devices.
For this video, I'm assuming you're already
familiar with the Cast developer console.
If not, please review the developer
console documentation.
Now, let's take a look at what a receiver application is.
Cast receiver applications are single-page HTML5 apps
that are loaded from a network URL
and executed on a special version of Chrome.
Cast receiver applications run on Cast receiver devices
like a Chrome Cast.
Elements such as buttons, links, and alerts
have been disabled since there's no mouse or keyboard
input available.
All interactions with a running Cast receiver application
happen through messages sent by a Cast sender app.
To illustrate this interaction model,
let's take a look at how a Cast receiver
application is launched.
Cast receiver applications are launched
when a Cast sender application running
on a sender device such as a phone, tablet, or computer
tells a receiver device that it wants to launch an application.
What that application is depends on the application ID
that the sender provides when requesting
to use the receiver device.
The receiver device will look up the application ID using
a Google service and load the corresponding receiver
application associated with it.
Once the receiver application is loaded,
it can start processing messages from the connected sender
applications.
As a developer, you have options when
it comes to the type of receiver application launched
by a sender.
An application ID is a unique ID for a receiver application
that you get when you register a receiver
app in the Cast developer console.
You can register an application ID at cast.google.com/publish.
There are three types of receiver applications,
two of which require registration using
the Cast developer console, and one that does not.
The one that doesn't is called the Default Media Receiver,
and all it does is play simple media.
No styling, no customization, and no application ID.
There's no way to modify its behavior.
The Styled Media Receiver application
does require registration and allows for some customization.
It's for playback of simple media.
More on this in a moment.
Custom Receivers are applications
that require registration and are for building advanced media
players or other types of TV applications like games.
A Styled Media Receiver allows a sender application
to play media on a Cast device without needing
to create your own Custom Receiver application.
You can customize the Styled Media Receiver color
scheme and branding by providing your own CSS
during registration.
The Styled Media Receiver is a great way
to get started building Google Cast applications.
Using the Styled Media Receiver means
developers can focus their efforts on sender application
interactions without having to build a custom receiver.
Creating a Styled Media Receiver is
as easy as registering for an application ID
through the Cast developer console.
The Styled Media Receiver is the best option
if the application does not need to utilize advanced media
playback capabilities such as adaptive streaming, DRM,
closed captioning, or authentication.
Custom Receiver applications are the way
to go if you want to have control
over all aspects of the behavior of your application.
With Custom Receivers, you can support protocol name spaces
beyond just media and build rich experiences for your users.
You have full control over the presentation, interactions,
and more.
Using the Google Cast receiver SDK,
you can build an HTML5 application, hook
into the various events that are fired within the Cast Receiver
Message System, and build complex behaviors
beyond simple media playback.
The Cast Receiver APIs provide ways for developers
to build rich applications targeting the TV space.
You can utilize the Cast media player library
to build media applications that use adaptive streaming.
HLS, MPEG DASH, smooth streaming, and more.
They can also handle authentication and use DRM.
In order to load a receiver application onto a Cast device
while developing, register the receiver devices
you wish to use in the Cast developer console.
For an unpublished receiver application,
only registered Cast devices will
be able to load the receiver application.
As well, during development, the receiver device
will need to expose its serial number.
This can be enabled using the Chrome Cast setup application.
Simply select the Cast device and enable the "Send serial
number when checking for updates" option.
When you publish your application,
any Cast receiver device can load your app.
Now that I've covered some of the basics of setting up
for development, let's have a look at some code.
In a few lines of code, a very basic Custom Receiver
application can be built that plays simple media.
First, we load the receiver APIs.
Then we ensure that we have a video element, some media
element to play back video, music, et cetera.
Once the window onload is fired, identify the media element
and create a Cast media manager to handle the sender
communication and media events.
Then get an instance of the Cast receiver manager, which
is responsible for communicating with the Cast system.
And tell it to start, which lets the receiver device know
that the application is loaded and ready to process sender
messages.
From here, you can build up additional application logic.
And as you do, you might want to know
how to debug your receiver code.
Thankfully, it's very simple to debug receiver applications.
You can connect to a device debugger
on a registered receiver by opening Chrome on a computer
and going to the IP address of the receiver device
on port 9222.
You can get the IP address of the receiver device using
the Chrome Cast setup app.
The debugger has full DOM manipulation and JavaScript
console support.
To keep logs between sessions, click the gear icon
in the lower right and check the box next to "Preserve
log upon navigation."
We are very excited to see what you build with Google Cast.
To get you going, we're providing
a number of resources.
You can discover more details about the Google Cast SDK
at developers.google.com/cast.
The design checklist will go a long way in guiding you
down the path to creating great second screen applications.
You can find sample senders and sample receiver apps
at gethub.com/googlecast.
Post your questions on Stack Overflow
and tag them with Google-cast.
In future DevBytes, we will dive deeper
into the Cast sender SDK for each platform and Cast receiver
SDK.
Join the Google Cast developer community on Google+ for pro
tips and share your experiences.
It's now up to you to go out and create great Google Cast
receiver applications.
Happy casting.