A YouTube player for Android TV
You can easily add this library to your app through JitPack.
build.gradle
:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
app/build.gradle
:
dependencies {
compile 'com.github.itvlab:youtube-tv-player:0.2.1'
}
Since the standard Android YouTube SDK doesn't work for video playback, this uses a WebView
and loads the YouTube URLs using their embedded URL. Then, playback is controlled through JavaScript.
This project includes the TIF Companion Library and automatically implements the TvPlayer
interface, so it's easy to include this in your Live Channel app.
The YouTubePlayerView
is an extension of the AbstractWebPlayer
and is both a media player (implementing TvPlayer
) and a view. You can instantiate it, load a YouTube video id, and include an event handler to do things once I am done.
mPlayer = ((YouTubePlayerView) findViewById(R.id.player_youtube));
mPlayer.loadVideo("kjEmkdrdRtI");
mPlayer.registerCallback(new TvPlayer.Callback() {
@Override
public void onCompleted() {
super.onCompleted();
mPlayer.loadVideo("kjEmkdrdRtI");
}
});
You can create a YouTubePlayerView
as the session's overlay view. Then, when you want to play a program, load the desired video and enable the overlay view. This will start playing your video without needing to handle a surface while giving you full access to playback controls.
If you want to add DVR functionality, you can simply save bookmarks to the desired video and play it later without having to download it and do disk management.
Sure! You can create a new class which extends AbstractWebPlayer
and implement the necessary methods. Do a pull request with a different player and it'll be added to the library.
You can check out SubChannel to see an example of this library in action.
- Missing some advanced YouTube features.
- Some videos won't play due to copyright restrictions. This isn't handled.