AMP Android SDK: Freewheel Integration

Document created by Jason Gamboa Employee on Jan 3, 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 AMPFreewheelSample Android Studio sample project in the release package.
To integrate the plugin into your app, you need to:

 

1) Add the amp-ads-freewheel.jar and FWAdManager.jar to your project's /libs folder.
 

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

import com.akamai.ads.IAdsComponentListener;
import com.akamai.freewheel.FWAdComponent;

 

3) Add an object of the FWAdComponent type in your Activity's members:

private FWAdComponent fwAdComponent;

 4) Make your Activity implement the IAdsComponentListener. This interface gives access to a set of callbacks linked to the ads behavior:

 

@Override
public void onAdsEnded() {
}

@Override
public void onAdsTrackProgress(int i) {
}

@Override
public void onAdsPlayheadUpdate(int i) {
}

@Override
public void onAdsError(String s) {
}

@Override
public void onPauseContentRequested() {
}

@Override
public void onResumeContentRequested() {
}

@Override
public void onAdsLoaded() {
}

@Override
public void onAdsStarted() {
}

@Override
public void onAdsPaused() {
}

@Override
public void onAdsResumed() {
}

5) Initialize and configure that object, on the onCreate() method from the Activity's life cycle as follows:

 

 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

      .
      .
      .
    fwAdComponent = new FWAdComponent(this,fwNetworkId,fwAdsURL,fwSiteSectionId,fwVideoAssetId,fwProfile);
    fwAdComponent.addEventListener(this);
    fwAdComponent.setVideoContainer(mVideoContainer);
}

 SideNote: The values required to implement your Freewheel Ads can be provided in two ways, first, by passing them as parameters using the constructor in the sample; and, by using Configuration files, the values can be provided from there as well, in that case, the generic  FWAdComponent() must be used since the values are being already retrieved from the Configuration. For more details please visit the Configuration Files User Guide.

 

6) Set the VideoPlayerView object to the FWAdComponent object when the onResourceReady(MediaResource resource) callback is triggered as follows:

 

@Override
public void onResourceReady(MediaResource resource) {
      .
      .
      fwAdComponent.setVideoPlayerView(mVideoView);
      .
      .
}

7) Add the following line to the onDestroy() method of the Activity's life cycle:

 

@Override
protected void onDestroy() {
super.onDestroy();
fwAdComponent.onDestroy();
}

 

Optional:

 

You can add the following implementation to the onResume() and onPause() methods of the Activity's life cycle, yo implement automatic pause and recovery of the Ads in case the App implementing the Ads loses its foreground status.

 

@Override
protected void onResume(){
    fwAdComponent.onResume();
    super.onResume();
}

@Override
protected void onPause() {
    fwAdComponent.onPause();
    super.onPause();
}
1 person found this helpful

Attachments

    Outcomes