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

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 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 'com.google.android.gms:play-services-cast-framework:10.0.1'
compile 'com.android.support:mediarouter-v7:24.2.1'

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;
import com.google.android.gms.cast.CastDevice;
import com.google.android.gms.cast.CastMediaControlIntent;
import com.google.android.gms.cast.MediaStatus;

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:

 

@Override
protected void onStart() {
super.onStart();
mCastManager.onStart();
}

public void onStop() {
super.onStop();
mCastManager.onStop();
}

 

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

mCastManager.addCastListener(this);

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

public boolean onCreateOptionsMenu( Menu menu ) {
super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem mediaRouteMenuItem = menu.findItem( R.id.action_cast );
    MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat.getActionProvider( mediaRouteMenuItem );
    MediaRouteSelector routeSelector = mCastManager.getMediaRouteSelector();
    mediaRouteActionProvider.setRouteSelector(routeSelector);
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

Attachments

    Outcomes