AMP Android SDK: Chromecast Integration

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


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 ChromecastSample Android Studio sample project in the release package.
To integrate the plugin into your app, you need to:


1) Add the amp-ott-chromecast.jar to your project's /libs folder.


2) Add the following lines to your build.gradle file:

compile ''
compile ''

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

import com.akamai.chromecast.CastListener;
import com.akamai.chromecast.CastManager;
import com.akamai.chromecast.CastUtils;
import com.akamai.chromecast.SeekBarManager;

4) Add the following attributes to the activity:


private SeekBarManager mSeekBarManager;
private CastManager mCastManager;

5) Create an instance of the CastManager in your onCreate() method:


mCastManager = new CastManager(getApplicationContext(), CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID, this);

6) After the playback has started, create an instance of the SeekbarManager on the onResourceReady() callback, to receive the events related.

mSeekBarManager = new SeekBarManager(mVideoView, mCastManager, mSeekBar, MainActivity.this);

7)  Add the following lines to your onStart() and onStop() implementation:


protected void onStart() {

public void onStop() {


8) Implement the following callback type CastListener  and set it yo the CastManager as follows:


9) Implement the following code on your onCreateOptionsMenu() to enable the Casting option on your activity:

public boolean onCreateOptionsMenu( Menu menu ) {
    getMenuInflater().inflate(, menu);
    MenuItem mediaRouteMenuItem = menu.findItem( );
    MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat.getActionProvider( mediaRouteMenuItem );
    MediaRouteSelector routeSelector = mCastManager.getMediaRouteSelector();
return true;


This Manager handles the playback during casting using AMP, however, the module does not provide an UI for seeking, playing and pausing the casting. You can create your own UI and adjust it to our module. Our Chromecast Sample showcase this scenario, please refer to it for a better understanding of the module.


1 person found this helpful