Android AMP SDK Migration Guide: From v5 to v6

Document created by Orlando Sanchez Martinez Employee on Feb 7, 2017Last modified by Orlando Sanchez Martinez Employee on May 5, 2017
Version 6Show Document
  • View in full screen mode

This document is part of AMP Android SDK 

 

 

When migrating from an older version to our latest, the changes needed for basic playback are minor:

 

 

 

1) Playing a stream

Previously, the developer had to know all about the different decoding modes included in the SDK, to choose an appropriate one for the stream to be played:

// Old

String mUrl = ...;

if (mUrl.endsWith(".mp4")) {
   
mVideoContainer.setMode(VideoPlayerContainer.MODE_NATIVE_BASIC);
else {
   
mVideoContainer.setMode(VideoPlayerContainer.MODE_HARDWARE_ADVANCED); 

}
mVideoView.playUrl(mUrl);


Now on v6, the SDK automatically selects the best decoding mode, according to the specific device and stream (by analyzing its metadata and MIME type).

 

To play the video and do this automatic analysis, there is a new async callback:

 

// New

mVideoContainer.addVideoPlayerContainerCallback(new VideoPlayerContainer.VideoPlayerContainerCallback() {
    @Override
   
public void onVideoPlayerCreated() { Log.i(TAG, "onVideoPlayerCreated"); }

    @Override
   
public void onResourceReady(MediaResource resource) {
        mVideoView = mVideoContainer.getVideoPlayer(); //Mode set automatically
        mVideoView.setLicense(LICENSE);
        mVideoView.play(resource); //Start playback
    }

    @Override
   
public void onResourceError() { Log.e(TAG, "onResourceError"); }
});
mVideoContainer.prepareResource(VIDEO_URL);


Notice you can get (or set) information about the stream on the com.akamai.media.elements.MediaResource class:

String url = resource.getResourceUrl();
String mimeType = resource.getMimeType();

mediaResource.setCategory("MyCategory");
mediaResource.setDrmUrl(WIDEVINE_URL);

 


2) Play a stream at a specified position (in seconds)

 

Apply a similar change, using the play(url, position) method of the async callback.

Previously, the call to play was done using the URL of the stream (the first parameter is a String):

// Old

mVideoView.playUrl(mUrl, mCurrentPositionInSeconds);

 

Now, we use the MediaResource itself, which is received as parameter, on the onResourceReady() method, from the VideoPlayerContainerCallback:

// New

mVideoView.play(resource, mCurrentPositionInSeconds);

 

 

3) Getting the VERSION of the AMP Library

// Old

String ampVersion = VideoPlayerView.VERSION;

  

// New

String ampVersion = AMPLibraryInfo.VERSION;

 

You can also get the library's "official name" from the AMPLibraryInfo.NAME constant.

 

 

4) Events

 

Here listener is of the type com.akamai.media.IPlayerEventsListener.

We have added the possibility to add several different events listeners, and also to remove them:

 

// Old

mVideoPlayerView.setEventsListener(listener);

  

// New

mVideoPlayerView.addEventsListener(listener);

//...do some more work...

mVideoPlayerView.removeEventsListener(listener);

 

 

5) Decoding modes

 

The SDK automatically determines the best decoding mode available.
However, if you want to change it for testing, compatibility (or for any other reason), here’s how:

// Old

mVideoContainer.setMode(iPlayerMode);

 

// New (the best practice is NOT calling this method)

mVideoContainer.setDefaultMode(iPlayerMode);

 

Read more about the different decoding modes here.

 

This document is part of AMP Android SDK

Attachments

    Outcomes