Background Playback using AMPPlayer

Document created by Jason Gamboa Employee on Apr 13, 2018Last modified by Jason Gamboa Employee on Apr 13, 2018
Version 11Show Document
  • View in full screen mode

Prerequisite

The rest of this guide assumes you have successfully set up the player using the AMPPlayer object.

 

Getting started

When you enable background playback in AMP, you will see the following behavior:

-When sending the App to the background, will continue listening to the audio, even if the stream contains video as well.

-A notification control will appear where you can interact with the playback when backgrounded.

-You can return to the view at anytime when tapping on the notification.

 

To enable this functionality you need to:

1) Set the binding context to the player on the onCreate method of the Application class of your project:

AudioServiceManager.getAudioServiceManager().setBindingContext(this);

 

2) Set the allowBackgroundPlayback flag as true in the configure method:

amp.configure(this, AMP_LICENSE, customButtonsCallback(), true);

 

2.1) Make sure the onStart method is called in your implementation, it is required to bind the playback to a the specific view your are instantiating the player.

@Override
public void onStart() {
    if (amp != null) amp.onStart();
    super.onStart();
}

 

3) Call the following method to make sure the background service running the playback gets stopped when the onDestroy method is called:

amp.setUnbindServiceOnDestroy(true);


4) If you prefer, you can set the title, subtitle and image to display in the notification as follow:

amp.setPlaybackInfo(new PlaybackInfo.Builder()
        .setSubTitle("Subtitle")
        .setSubTitle("Title")
        .setSmallIcon(R.mipmap.ic_launcher)
        .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.icon))
        .build());


Attachments

    Outcomes