AMP Android SDK: Android TV UI Integration

Document created by Jason Gamboa Employee on Jan 6, 2017Last modified by Herberth Alvarado on Apr 9, 2017
Version 6Show Document
  • View in full screen mode

Prerequisite

The rest of this guide assumes you have successfully integrated AMP's Core (you are able to play back a video). 

 

Getting started

For reference, check the TVUISample Android Studio sample project in the release package.
To integrate the plugin into your app, you need to:

 

1) Add the amp-ui-tv.aar to your project's /libs folder.
 

2) Copy the following lines in your runnable module build.gradle file

compile(name:'amp-ui-tv', ext:'aar')
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:leanback-v17:23.3.0'

3) In the Activity where playback is handled, import the following Java packages:

 

import com.akamai.uitv.MediaControlBarManager;
import com.akamai.uitv.MediaPlayerController;

4) Implement the MediaControlBarManager.OnRemoteControlActionsListener callback in the Activity that handles the playback, this will allow you to receive actions related to the TV's remote control:

@Override
public boolean onRemoteActionReceived(MediaControlBarManager.RemoteControlAction action){
switch (action) {
case PLAY:
return true;
case PAUSE:
return true;
case FAST_FORWARD:
return true;
case REWIND:
return true;
case CAPTION_ON:
return true;
case CAPTION_OFF:
return true;
default:
return false;
    }
}

 

5) Implement two instances of the following objects:

private MediaPlayerController mediaPlayerController;
private MediaControlBarManager mediaControlBarManager;

6) Create a View type fragment on the activity's xml layout as follows:

<fragment
    android:id="@+id/playback_controls_fragment"
    android:name="com.akamai.uitv.MediaPlayerController"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

7) Create an instance of the Fragment controller in the code as follows:

 

mediaPlayerController = (MediaPlayerController)
        getFragmentManager().findFragmentById(R.id.playback_controls_fragment);

8) On the onResourceReady() callback, create an instance of the Controller Manager and set the VideoPlayerView object to it:

 

mediaControlBarManager = new MediaControlBarManager(this, this, mediaPlayerController);
mediaControlBarManager.setVideoPlayerView(mVideoPlayerView);
1 person found this helpful

Attachments

    Outcomes