Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Youtube API in Android TV

I want to play youtube videos in my Android TV APP. I am also working on a Android phone/tablet APP and I was able to use Youtube Android API to play videos. But when I try to use the same API on Android TV it gives me an error ("This app won't work unless you update the YouTube"), but my youtube is updated.

I found this issue in the YouTube Android Player API issue tracker, it is the same problem that I am facing here, so I want to know if someone have a solution, or know another version of the API that may work. I am using YouTube Player Android API v1.2.2.

I know that I can open youtube via Intent, but I need to use the YouTube API to show videos.

like image 414
mpostal Avatar asked Mar 23 '16 17:03

mpostal


2 Answers

The YouTube playback API may not work on Android TV, but you can always implement your own playing mechanism in-app. Take a look at YouTube's web player API: https://developers.google.com/youtube/iframe_api_reference

You can load a WebView in your app and from there add an iframe and JS logic to integrate with your controller.

To interface between your JS and Java code, take a look at a project like this: https://github.com/Fleker/WebGameBridge.js for how to use the WebView APIs.

In terms of getting data, there are also web APIs for this that you can access through your WebView.

like image 119
Nick Felker Avatar answered Oct 04 '22 08:10

Nick Felker


I've created YoutubeTV library, a wrapper for YouTube Player API Reference for iframe Embeds

It provides a YoutubeTvView that embeds a Webview with Youtube iframe with all Javascript API available from this view.

Also, YoutubeTvFragment holds a YoutubeTvView with a media control bar (PlaybackOverlayFragment)

like image 23
Bertrand Martel Avatar answered Oct 04 '22 08:10

Bertrand Martel