Enhancing The Experience With Android TV: Briefly About One Developer's Impressions





527

We aggregate and tag open source projects. We have collections of more than one million projects. Check out the projects section.

In my software development career, I have always been attracted to new technologies and innovative solutions. Project by project, I have been exploring something new, discovering and implementing different approaches and trying new solutions. When Android TV showed up, I set a new personal goal.

I described my impressions and the overall opinion on the application development for Android TV right here. Hope you will find it useful and interesting.

Android TV: What Is New?

For those who have been sleeping in a cave, I have written a few words concerning Android TV basics. Android TV was announced at one of the greatest events in the IT world. Google I/O 2014 offered us a glimpse at it, and later, in the autumn of 2014, a hardware device that supports the technology was released.

Android TV is a type of Android OS created for digital media players, TV and set-top boxes.

In a nutshell, Android TV has brought the entertainment from a smartphone to a TV. Let’s take a look at the main features of this technology:

Android TV Is Easy To Use

If you do not agree with this statement, just go to Youtube or The Walking Dead channels and devote some time to the tutorials. When you turn the device on, you get the opportunity to use a convenient navigation that leads you directly to what you need.

Search Features Are Amazing

Hardware for Android TV recognizes the human voice. This makes searching a lot easier. With the help of this feature, you can start a video within seconds or perform more complicated actions like getting the list of 2018 Oscar nominations.

Google Assistant

Yes, you can have your reliable assistant on a TV, too! Since January 2017, Google Assistant is available on Android TV.

High-Quality Content

With Android TV, you have access to such apps as Netflix, BBC iPlayer and many others. Additionally, the technology is supported by the manufacturers’ apps. For example, if you use Sony TV, you can get the access to Sony Select. Google Play Store is at your disposal, too.

Google Play Games

Besides the applications, Android TV supports various games. You can play both online and offline, choose single-player or multiplayer games, save your progress and enjoy playing on a big screen.

This is not a full list of features available on Android TV. Additionally, you can use various settings to customize the technology on your device, send media from your smartphone to your TV and try other useful features.

Android TV Application Development Experience: My Impressions

I could not resist the temptation to take part in a test project when such an opportunity appeared.

To setup Android TV support to your project, you need to modify the AndroidManifest.xml file. Add the following lines of code:

<uses-feature android:name="android.hardware.touchscreen" android:required="false" /> <uses-feature android:name="android.software.leanback" android:required="true" />

Additionally, declare an appropriate IntentFilter for activity:

<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> </intent-filter>

This is how we can declare that the project does not support touch-screen controls and is able to interact with the Leanback interface elements.

Leanback Interface Specifics

Leanback library was created to simplify the process of integrating the technology. It differs from the usual Android apps interface.

The fact that the Leanback library UI elements were designed and built for devices without any touch-screen controls led to certain consequences. View has got an important intermediate state - selected. Usually, this state is not a big deal when used on Android apps. The Selected state informs the users which element they are interacting at the moment. It can be either a button or a list element.

Leanback Library offers various ready-made instruments. Here is the list of the most significant ones:

BrowseFragment,

RowFragment,

DetailsFragment,

VerticalGridFragment,

SearchFragment, etc.

The Leanback library provides the opportunity to display different data collections in the form of lists or tables. I have some RecyclerView development experience for standard Android apps in the past. So, it was rather interesting to see how Android TV implements the same functionality.

Presenter is an Android TV analog for RecyclerView.Adapter. Presenter can interact with ArrayObjectAdapter to display data in the form of tables.

Classes Hierarchy with BrowseFragment

In our project, we needed to display double-nested objects. At the same time, it was necessary to take care of optimized navigation for the user. BrowseFragment solved this task perfectly.

This Leanback library component displays the list of the objects on the left and the internal data of those objects in the table rows on the right. Below you can see what the hierarchy of classes for displaying data looks like:

ArrayObjectAdapter -> ArrayObjectAdapter -> Presenter

Let me explain this line. Presenter is responsible for displaying the ImageCardView objects. ImageCardView includes the image, title and subtitle. ArrayObjectAdapter is responsible for every row of the table. It manipulates the data and binds it to View-elements with the help of Presenter. ArrayObjectAdapter is also responsible for displaying the rows vertically. ListRowPresenter places the elements where they should be.

HLS-Link Video Streaming with ExoPlayer

Displaying a great volume of content was really fascinating. However, there was another challenging task when we were developing this project - video streaming via the HLS-link. So, let’s clarify the basics first.

HLS, or HTTP Live Streaming, is a communication protocol for streaming media. As you already know, it is based on HTTP. The protocol was developed by Apple and initially was included in Safari, QuickTime, OS X, iOS etc. The protocol is based on dividing the whole stream into smaller fragments which can be downloaded consistently via HTTP. The flow is continuous. Theoretically, it can even be never-ending.

After a comprehensive research, I have come to a conclusion that ExoPlayer is a nice choice for video streaming. The player has a convenient extension for Android TV. What to do to connect it? Just add the following lines to build.gradle:

api "com.google.android.exoplayer:extension-leanback:$versions.exoplaye"

api "com.google.android.exoplayer:exoplayer:$versions.exoplayer"

I wrote some simple code to enable ExoPlayer to open and play an HLS-link.

private void prepareMediaForPlaying(String hls) { DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getActivity(), Util.getUserAgent(getActivity(), getString(R.string.app_name))); HlsMediaSource videoSource = new HlsMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.parse(hls)); player.prepare(videoSource); }

A Few Words for the Beginners

Participation in this project was impressive and impactful. The point is, I created a brand new solution using the knowledge I already had. And it was great!

Now, I can say that every Android developer can easily deal with Android TV.

And last but not least, I would recommend you to get familiar with the following things before you start diving into Android TV development depths:

Android TV Official Documentation

You are literally helpless without reading the official documentation. So, devote some time to it to make your development experience pleasant.

Keep Your Hand On The Pulse

Google pays a lot of attention to Android TV development and improvement. So, check the official page to find out about the updates, news and essentials regarding how to use it.

Visit Github

Android Leanback and Leanback Showcase are sample projects uploaded to Github. Visit the pages and make sure by yourself!

My experience with Android TV was seamless and precious, so I wish the same to you! You can check our Android TV project and get the inspiration to expand your knowledge.

Reference:

https://developer.android.com/tv

https://developer.android.com/guide/topics/media/exoplayer

https://github.com/googlesamples/androidtv-Leanback