LEON NICHOLLS: Do you want to get your Android
apps on the big screen?
Well, we've made it easier than ever before.
Hi.
I'm Leon Nicholls from the Google Developer Relations
Team, and I'm going to tell you about the Google Cast SDK
Version 3 for Android.
In June 2016, we launched the new version 3 API
for the Google Cast SDK.
The new Cast SDK simplifies several parts
of the previous SDK and addresses the major pain
point identified by content partners and developers
like you.
The new Cast SDK significantly reduces the amount
of code needed by providing UI widgets that
fully comply to the Cast UX design checklist.
First, here is some terminology about how casting works.
The Cast sender application refers to an app
on a mobile device or a laptop.
And a receiver application case and refer to an HTMI
application running on Chromecast or other Google Cast
receiver devices.
Let's take a look at the typical lifecycle of a cast sender app.
When the sender app is launched, Cast receiver devices
need to be discovered on the local network.
Once the user selects a device, a sender app
will connect to their device and launch the receiver app.
The sender app then creates a message channel
to the receiver.
The user can also disconnect from their device at any time.
The new SDK is based on the design of the Cast companion
library and implements these new features.
First, the UI widgets that comply with the Google Cast
design checklist, notification and lock screen controls,
automatic device discovery so you
don't have to manage that in your code,
centralized Cast system state management,
and a reconnection service that automatically handles
network issues to keep your sender app
connected to the receiver.
So even when the user leaves the room,
goes out of the range of the network,
the system will be automatically reconnected
when the user returns.
The Google Cast SDK is still part of Android's Google Play
services and is shared across all Cast apps.
The minimum Android SDK level that the Cast SDK supports
is level 9 or Gingerbread.
In Android Studio, make sure these necessary libraries
are installed.
Let's take a look at how to add Cast to your app.
The Cast framework has a global singleton object,
the Cast Context which coordinates
all the Cast's interactions.
You must implement the options provide
interface to supply Cast options needed to initialize the Cast
Context singleton.
The most important option is to receive
application ID, which you get from the Google Cast Developer
Console.
You can get to the Cast Context instance
by using the static getSharedInstance method.
If you've used to v2 SDK before, you must be wondering,
where is the Google API client?
That's not needed anymore to use Cast.
Everything is done for you by the v3 framework.
For your app's UI, the first step in supporting Cast
is to add the Cast button.
The SDK provides a Cast button widget
that automatically manages its visibility and state
and provides all the necessary dialogs for users
to select and disconnect devices.
The Cast button is implemented by the media route button
from media route of version 7 support library.
Like any action icon that you can
add to your activity-- using an action bar or a tool bar--
you first need to add the corresponding item
to your main you.
Once you've done that, override the onCreateOptionsMenu method
of each of your activities by using the Cast button factory
to wire up the media add button to the Cast framework.
When the user selects a Cast device using the Cast button
menu, the new Cast session is started automatically
by the framework.
All the user interactions, including
backing out of this menu, are handled by the widget.
The list of devices is [INAUDIBLE]
based on the app ID configuration in the Google
Cast Developer Console.
For the Cast framework, a Cast session
encapsulates the connection to a device,
managing the receiver application,
and initializing a media control channel for media apps.
Cast sessions are managed by the system manager which can be
accessed via the Cast context.
The system manager listener callbacks
can be used to monitor session and main status, creation,
suspension, resumption, and termination of the session.
To play media on the receiver, the send app
has to provide media metadata of the media stream.
Here you can see how to set the media type, title, and images
using the media metadata class.
Here you can see how to set the media URL, stream
type, and other metadata using the MediaInfo Builder class.
The remote media client class is then
used to load that media stream on the receiver.
The send app then invokes commands
such as play and pause using the remote media client instance.
The send app can use the system manager listener callbacks
to track the session state and determine
when to enable and disable the local media player.
Playing media on the receiver is now a breeze.
The Cast SDK provides a widget called the Mini Controller that
appears when the user navigates away from the current content
page to another part of the app.
The Mimi Controller provides instant access
and is a visible reminder for the current Cast session.
The Cast SDK provides a custom view Mini Controller fragment
which can be added to the app layout
file of the activities in which you want
to show the Mini Controller.
This is so much easier than the v2 SDK
where you had to create the Mini Controller yourself.
The Google Cast design checklist requires a send app
to implement media controls from a notification
and the lock screen.
This is allows users to always be
in control of the media session with convenient playback
control buttons.
The Cast SDK provides a media notification service
to help the sender build these controls for the notification
and lock screen.
The media notification service will run in the background
when the sender is Casting and will show a notification
with an image thumbnail, metadata
about the current Casting item, a Play/Pause button, and a Stop
button.
Here you can see how the notification and lock screen
controls can be enabled with the Cast options
when initializing the Cast context.
Notifications are then managed for your app
by the Cast framework.
It's that easy.
The Google Cast design checklist requires the sender
to provide an expanded controller
for the media being Cast.
The expanded controller is kind of like a full-screen version
of the Mini Controller.
The Cast SDK provides a widget for the expanded controller
called the Expanded Control Activity,
which is implemented as an abstract class.
To add an expanded controller, subclass
ExpandedControllerActivity and add a Cast button.
After you've done that, edit the Cast options provider
and change the notification options and Cast media options
to set the target activity to your subclass of the Expanded
Control Activity.
The expanded controller widget will save you a lot of code
if you've used the v2 SDK before.
Now that you've integrated Cast with your app,
how do you tell your users about it?
Well, the Cast SDK provides a custom view
called Introductory Overlay.
That can be used to highlight the Cast button when it's first
shown to the user.
This code shows you how to use the IntroductoryOverlay
Builder to show the overlay in your activities.
That's everything you need to Cast enable your sender app.
You can get a lot more details about the Google Cast SDK
at developers.google.com/cast.
We've also open sourced several 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+ to keep up
to date with the new SDK features.
Happy Casting.
[MUSIC PLAYING]