TV and media centre

Boring! Again there is nothing to see on the TV! At least not something that seems to be interesting enough. Smart TVs running on Android create a whole new interesting world for developers. Finally, we get the screen size we deserve!

However, it also comes with a different type of audience. Users interact with their phones and tablets to a very large extent. When it comes to watching TV, the focus is much more on consuming.

Well, what is there on the TV? Have a cup of tea and start watching the show. Occasionally, users might be interested in some interaction (a phenomenon that mostly appears as a second screen app since not anyone does own a smart TV already), but most of the time, TV watchers just want to lean back.

Getting ready

This recipe requires Android Studio up and running and the latest SDKs installed. In this recipe, we will provide you a brief introduction to a TV app. In only a few steps, we will create a media centre app. Don't worry, you do not need to have an Android TV. We will create a virtual one.

How to do it...

Let's see what we need to do to develop an Android TV app:

  1. Create a new project in Android Studio. Name it PersonalTeeVee and click on the Next button.
  2. Select the TV option and click on the Next button.
  3. Choose Android TV Activity and click on Next.
  4. Enter TeeVeeActivity in the Activity Name field and Personal Tee Vee in the Title field and click on the Finish button.
  5. Android Studio creates a phone and a TV module for you. Change the configuration to TV. You will see something as shown in the following figure:
    How to do it...
  6. Check out the AndroidManifest.xml file in the tv module. Note the lean back feature requirement (which tells us that this is a TV app with fullscreen experience without any heavy interaction and basically is about consuming content such as watching a video). Also note that we do not require a touch screen. The TV screen is too far away to touch. Besides, nobody likes smears on their TV screens:
    <uses-feature
    android:name="android.hardware.touchscreen"
    android:required="false" />
    <uses-feature
    android:name="android.software.leanback"
    android:required="true" />
  7. To test the TV app, we need to have a virtual TV device. Open the AVD manager option from the Tools | Android menu.
  8. Click on the Create Virtual Device button.
  9. Select TV from the category list and choose a TV device (1080p or better). Click on the Next button.
  10. Pick a system image. I chose, for example, API level 22 x86. Click on Next.
  11. Modify the name of the AVD to whatever you think suits best and click on the Finish button. A new virtual TV device will be created for you.
  12. Start your TV device by clicking on the play button. If it says that Google Play Services has stopped, you may ignore this message for now (although you will need it if you want to play a video).
  13. Once the device is booted, run your TV app from Android Studio. By default, it looks like this:
    How to do it...

Wow, this is a fully functional media centre app already!

This was just a brief introduction to building an Android TV app. Play with it and tweak it.

There's more...

While the app in this recipe is dedicated to a TV, I see no reason why you couldn't make it an app for any kind of device: phone, phablet, and TV. If you want, you can combine all the recipes in this chapter into a single app. That's a nice challenge, isn't it?

Besides YouTube, there are also interesting media-related APIs to investigate. On www.programmableweb.com, for example, you can find some interesting APIs. Some of them are listed here:

API

Navigation

YouTube

http://www.programmableweb.com/api/youtube-live-streaming

Vimeo

http://www.programmableweb.com/api/vimeo

Hey! Spread

http://www.programmableweb.com/api/heyspread

Pirateplay

http://www.programmableweb.com/api/pirateplay

Tinysong

http://www.programmableweb.com/api/tinysong

TwitVid

http://www.programmableweb.com/api/twitvid

Well, now we know where to get media items from, how to play them, and how to automagically create a media centre app.

Coming up next: let's create some media ourselves by capturing some images. See you at the next chapter!

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset