What I Did This Summer: Building a TIF Companion Library for Android TV

Today, on the Android Developers blog there’s the new TIF Companion Library which makes it a lot easier for app developers to build apps for Live Channels and monetize their content through linear video ads. You can take a look at the library on GitHub and check out the sample app to see an implementation.

Prologue

In the middle of May I left New Jersey, just after completing finals. I flew out to Mountain View, California, the headquarters of Google. There, I began my internship at Google.

I started the week of I/O, where I was quickly thrust into all of the new announcements that were being made like USB tuner support in the Live Channels app and the new set-top box from Xioami. It was a great chance to speak to developers about Android TV and everything that was coming to Nougat.

Following that, it was time for me to actually get working. I was on the team for Develper Relations on Living Room and IoT, the team that engages with the developer community on Google+ and develops sample apps on GitHub. I was to work on a small project that would benefit the team and developers as a whole. Given my familiarity with TV, that was the product I would be building upon.

After talking to various teams, we agreed that I would be building a companion library for the Tv Input Framework, the APIs that allows an app to work with the app Live Channels.

An example of an app using ChannelSurfer
An example of an app using ChannelSurfer

You may recall back in January when I published the project ChannelSurfer, which billed itself as a “Very simple Live Channels library for Android TV”. I rewrote the library from scratch, getting rid of some of the hacks and getting this new code up to Google’s standards. It’s definitely ready for developers to use, and it even supports the Tv Recording APIs introduced in Android Nougat.

What does it do?

There are three key sets of APIs that this library provides for developers:

Model

The Tv Input Framework allows an app’s channels and programs to be inserted to a master database which is ready by the system’s TV app. Database queries aren’t too intuitive in Java, where things are generally object-oriented. These database calls aren’t checked, so it’s easy to add channels or programs with invalid parameters. This library introduces classes for Channel, Program, and RecordedProgram which hide certain parameters from being set and enforce certain parameters being set.

This improved checking allows developers to create these objects while running into fewer errors, and it’s easy to create your EPG data in your EpgSyncJobService and just return your objects without any database interaction.

Syncing

Your cable box will update roughly once a day with the latest program data. In a TIF app, this is a common feature. This process is simplified by creating a Service that extends the EpgSyncJobService. Then you can just return your list of channels and programs. The EPG syncing and database management boilerplate code is handled in the EpgSyncJobService class. It’s easy to set up this service to run periodically.

Easier Playback

There are a lot of common calls that a developer wants in their TvInputService, the core service that runs when a user tunes to a channel. There are database calls that should be made, turning the queries into your objects. You may want the program’s ratings to be checked with parental controls so that certain content isn’t seen. There is an inner class which provides common functionality around recording programs and channels. The goal is to reduce as much boilerplate as possible so that adoption of this platform is easier.

The addition of the TvPlayer interface makes it easier for time-shifting to just work and provide better encapsulation of features inside your media player.

Ads

Sample VAST ad that plays
Sample VAST ad that plays

Developers want to know how adding TIF support will benefit them. There are some examples, like HayStack, where adding TIF allowed them to achieve greater adoption. However, that doesn’t necessarily correspond to greater revenue. Part of this library is integrating linear video ads with VAST (video ad serving template). This will allow users to see commercials periodically, giving an incentive to adding TIF support. It’s easy to use with the Advertisement class and inserting ads into a Channel or Program.

I can’t take credit for this. Adding VAST support in this library was the work of another intern, Guangyu. His work should definitely encourage more developers to take a look at this feature.

Improvements over ChannelSurfer

As I began writing this library again and discussing the project with Google engineers, I was able to make a number of improvements over the original library. If you are using ChannelSurfer now, there’s many reasons to switch. It’s definitely going to be more stable thanks to automated tests which have been written, and the code has been vetted by more people than just me. Their comments were really helpful in produce a better final result.

Unbundling MediaPlayer

In ChannelSurfer, I bundled in an older version of ExoPlayer. This caused developers to have to be stuck with my dependency. If you wanted to use a newer version of ExoPlayer, you had to make a lot of independent changes to the library and maintain your own fork. It’s not ideal. However, having a built-in media player made it easy to support features such as time-shifting without the developers putting in a lot of extra work.

There’s a solution in this library which keeps the time-shifting implementation easy without relying on a specific player. A developer’s media player class can now implement TvPlayer and return your player in BaseTvInputService.Session.getTvPlayer. By passing this interface, the library can still handle playback controls without needing full access to your player class.

Support for other TV apps

sony z-series 4k tv

Support for Sony TVs was ongoing in ChannelSurfer and I had a number of bug reports. They don’t use the Live Channels app, but a similar app. As I did not have one, I was unable to properly make sure ChannelSurfer worked as it should have. This companion library has been successfully run and tested on Sony TVs and it should allow TIF apps to work across any system TV app.

Conclusion

I was given an amazing opportunity this summer to work at Google as an intern and meet all kinds of cool, smart people. Now that it’s ended, I’m even more excited about Android TV and the types of experiences third-party developers can create. I’ll write more about these experiences soon. In addition to the Sample Tv Inputs project, I made numerous bug fixes and feature additions to the Leanback Sample app including settings and an onboarding screen.

Live Channels was something I’ve called their “killer app”, and my time in Developer Relations was about making it easier to apps to work with Live Channels.

ChannelSurfer was along the right path, but there were a few flaws in how it was developed. That project is now being deprecated, in favor of Google’s official solution. The whole library is open source, so any issues can go there instead.

I think that with this library that removes boilerplate code, and ads allowing for easy monetization, creating a TIF app is easier today than ever. I look forward to seeing what the developer community builds. What kind of TIF apps do you want to see? Let us know in the comments below.

Nick Felker

Nick Felker

Nick Felker is a student Electrical & Computer Engineering student at Rowan University (C/O 2017) and the student IEEE webmaster. When he's not studying, he is a software developer for the web and Android (Felker Tech). He has several open source projects on GitHub (http://github.com/fleker)Devices: Moto G-2013 Moto G-2015, Moto 360, Google ADT-1, Nexus 7-2013 (x2), Lenovo Laptop, Custom Desktop.Although he was an intern at Google, the content of this blog is entirely independent and his own thoughts.

More Posts - Website

Follow Me:
TwitterLinkedInGoogle PlusReddit

  • With TIF companion library, is there an option to display a banner ad at the bottom of the screen? A lot of apps could benefit if they could monetize that way also.

    • Banner ads can be integrated too using an overlay view. But there’s no direct way to click on a banner ad, so it would be somewhat light on revenue.