Android TV: Building TV Channels

Android TV: Building TV Channels

The traditional way of
watching TV is channel surfing. You pick up the
remote, lean back, and flip through channels
to see what’s on. On Android TV, app developers
can create TV channels so your content can be
part of this experience. To the user, your
channels look and feel like regular TV channels. But behind the scenes, they
stream video off the internet. You can create a TV channel
from a video playlist and have it appear alongside
other channels in the program guide. The feature that
makes this possible is the TV input framework. This defines how
Android TV works with channels provided
by a physical TV tuner as well as streaming-based
channels provided by an app. To create a channel, there are
two main classes to implement. The setup activity
communicates with the system to provide information
about your channels, like what programs
are on and when. The TV input service,
on the other hand, receives events from the system. These events inform you
when the user interacts with your channel– for
example, when they tune to it or change the volume. The best way to learn
how to build a channel is to check out the Sample
app, which you can find linked in the description below. Install it, and you’ll
find it provides a TV input source that you can configure
through the Live Channels app. This creates a variety of
channels that fully integrate with the Program Guide. Each of these shows off
a different feature. Some stream video
from the internet using MPEG Dash or HLS. And others show
how to use features like closed captioning
in multiple audio tracks. Another great feature
the Sample demonstrates is called app linking. With app linking, you
can provide a direct link to your app from your channel. And this is a great way
to increase engagement. Now, let’s take a look at the
implementation at a high level. If you have an
existing app, then you can add support for
the TV input framework into your existing APK. As usual, start by updating
your application manifest. The first step is to declare
your TV input service, add the bind TV
input permission, and declare an intent filter
that specifies the TV input service. Within the service
declaration, you’ll also need to point to
your setup activity. And you can do that by
providing a link to meta data in a separate XML resource. Once your manifest
is updated, it’s time to implement your service. To do that, you extend the
TV input service class. Your service is started
by the system when the user tunes to your channel. And when that happens,
the onCreateSession method is invoked. Inside this method, you’ll
return a TV input service session object. This contains callback methods
the system uses to inform you of different events,
like when it’s time to begin playing
back your content. The first important
event is onSetSurface. This is used to provide
you with an Android surface object on which you
can play your content. And you can do that using
Android’s Media Player or ExoPlayer and
other media players. And by the way, if
you’re new to ExoPlayer, it’s a Google-maintained,
open-source alternative to Android’s Media Player API. When the user tunes to
one of your channels, the onTune callback is invoked. This signals it’s time to
start playback on that surface. There are additional
callbacks you can implement to handle
things like closed captions and parental controls. And you can find more details
about these at this link. Now in your set up
activity, you’ll need to provide
electronic program guide data, or EPG for short. This is just a list of
your channels and programs. It tells the system what
shows are on and when. Just like other media
data, Android TV keeps channel and
program information in content providers. Inside your set-up
activity, you’ll map your program information to
the fields Android TV expects. You can find details about
these fields at this link and see a complete example
and some utility classes in the Sample app. Over time, you’ll probably need
to update your program data. You can do that
in the background by using a built-in
solution like Job Scheduler. You can register your
job and run the update during idle time– say,
every night at 3:00 AM. For more information, check
out the Developer Training and the Sample app. And visit the
Android TV Community to ask questions
and share ideas. Thanks very much for watching,
and I’ll see you next time. [MUSIC PLAYING]


13 thoughts on “Android TV: Building TV Channels”

Leave a Reply

Your email address will not be published. Required fields are marked *