Fire TV
The latest THEOplayer Android SDK (5.0.0+) is compatible both with Android mobile and Fire TV. We do not have a separate SDK for each platform.
You can follow the guide: Getting started on Android.
This guide will help you to integrate the THEOplayer Android SDK into your Fire TV project.
To start this guide you need the following:
The THEOplayer Android SDK can be used for Fire TV devices using Android 5.0+ (minSdkVersion 21). Build your Android SDK through our portal.
Enable the ExoPlayer
but exclude the Chromecast
feature flags.
Clone the THEOplayer Android TV SDK - Starter project: https://github.com/THEOplayer/android-tv-sdk-starter-project or build your own, following these guidelines.
Make sure minSdkVersion
is set to 21 in app/build.gradle
.
There is no need to add any Amazon ExoPlayer dependencies, as these are built into the Fire TV SDK.
Your SDK will include a THEOplayer license which you must specify as part of your setup. Your player license can be defined in one of the following ways:
Passing the license through the PlayerConfiguration
// passing your license as a string
public static THEOplayerConfig.Builder getTHEOplayerConfigBuilder() {
return new THEOplayerConfig.Builder()
.license("your_license_here");
}
// passing your license as a URL
public static THEOplayerConfig.Builder getTHEOplayerConfigBuilder() {
return new THEOplayerConfig.Builder()
.licenseUrl("your_licenseUrl_here");
}
Passing the license through the manifest
Define your license
or a licenseUrl
as a new key in the app's manifest.
Our Fire TV SDK allows configuring the license via metadata keys, which could be either THEOPLAYER_LICENSE
or THEOPLAYER_LICENSE_URL
.
THEOPLAYER_LICENSE
must be an obfuscated license string.
THEOPLAYER_LICENSE_URL
must be a valid URL to a license server.
You can define your license string, in the AndroidManifest.xml
, which should look similar to the below snippet of code (replace THEOPLAYER_LICENSE
with THEOPLAYER_LICENSE_URL
if specifying the URL):
<application>
<meta-data
android:name="THEOPLAYER_LICENSE"
android:value="your_license_here" />
</application>
The license defined in the player configuration has higher precedence than the license provided in the app's manifest. If neither of these are defined, then the built-in license will be used.
Importing the THEOplayer Android SDK Library can be done following these steps:
Additionally, you can import the sources jar to be able to immediately see the API java source files with their documentation in Android Studio. Follow the following after successfully importing the library steps for that:
In order to use THEOplayer in a Fire TV app, you will need the THEOplayerView as the central component. This class can be loaded in a Layout and this will create a new player object for you to interact with.
Important:
AndroidManifest.xml
of your app needs to declare that it uses the internet permission.N.B. If you cloned the THEOplayer Android TV SDK - Starter project on GitHub, you can exclude this step.
public class MainActivity extends Activity {
// ...
@Override
protected void onPause() {
super.onPause();
tpv.onPause();
}
@Override
protected void onResume() {
super.onResume();
tpv.onResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
tpv.onDestroy();
}
// ...
}
When using XML to set your layout, you can add the following code to your XML file:
<com.theoplayer.android.api.THEOplayerView
android:id="@+id/theoplayer_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Once you have the THEOplayerView in your layout, you can get a reference to it by using the findViewById-method.
N.B. If you cloned the THEOplayer Android TV SDK - Starter project on GitHub, you can exclude this step.
Next to using XML to configure your view, you can also instantiate the view programmatically in Java. This can be done in the following way:
THEOplayerView view = new THEOplayerView(activity);
This view can then be placed inside another view and positioned in your layout.
N.B. If you cloned the THEOplayer Android TV SDK - Starter project on GitHub, you can exclude this step.
Once a player is created and set in your view, you can start interacting with the player instance using the THEOplayer API.
Create a SourceDescription object and set the player's source.
N.B. If you cloned the THEOplayer Android TV SDK - Starter project on GitHub, you can exclude this step.
SourceDescription sourceDescription = SourceDescription.Builder.sourceDescription("https://cdn.theoplayer.com/video/elephants-dream/playlist.m3u8")
.ads(
THEOplayerAdDescription.Builder.adDescription("https://cdn.theoplayer.com/demos/preroll.xml")
.timeOffset("10")
.skipOffset("3")
.build())
.poster("http://cdn.theoplayer.com/video/big_buck_bunny/poster.jpg")
.build();
tpv.getPlayer().setSource(sourceDescription);
This example shows you how to listen to the player play event.
N.B. If you cloned the THEOplayer Android TV SDK - Starter project on GitHub, you can exclude this step.
EventListener<PlayEvent> eventListener = new EventListener<PlayEvent>() {
@Override
public void handleEvent(PlayEvent event) {
System.out.println(event.getCurrentTime());
}
};
tpv.getPlayer().addEventListener(PlayerEventTypes.PLAY, eventListener);
This example shows you how to add listeners for your remote control.
N.B. If you cloned the THEOplayer Android TV SDK - Starter project on GitHub, you can exclude this step.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
boolean handled = false;
System.out.println("KEY --" + keyCode + " -- " + event.getKeyCode());
switch (keyCode){
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
if (theoPlayer.isPaused()) {
theoPlayer.play();
} else {
theoPlayer.pause();
}
case KeyEvent.KEYCODE_BUTTON_A:
// ... handle selections
handled = true;
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
// ... handle left action
handled = true;
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
// ... handle right action
handled = true;
break;
}
return handled || super.onKeyDown(keyCode, event);
}
```pass the license in the manifest