Adaptr

object Adaptr

Adaptr creates and manages a single AdaptrPlayer and associates it with an Android Service and Notification. By using this class, music playback may continue when your app is backgrounded, and playback controls will appear in a notification and the lock screen. Additionally, media controller events (play/pause, skip) will be honored automatically. If you don't want the Adaptr library to create a Service or handle Notifications, then you should create and manage your own instance of AdaptrPlayer, rather than use this class.

To use this class, call one of the initialize() methods as soon as your application starts. We recommend you do this in your Application.onCreate() method:

public class App extends Application {

public void onCreate() {
super.onCreate();

Adaptr.initialize(getApplicationContext(),"demo","demo");
}
}

That call will cause the AdaptrPlayer to immediately be created and also kick off a background thread to contact the Adaptr servers to determine what music the user has access to, if any.

Unless your app is using offline music, the AdaptrPlayer instance isn't useful until a response has been received from the Adaptr servers. To be notified as soon as it is known when music is available, your app should use the getPlayerInstance method, which will call your listener exactly once when music is deemed available or not:

public class MyActivity extends AppCompatActivity {
// ...

.@Override protected void onCreate(Bundle savedInstanceState) {
// ...
Adaptr.getPlayerInstance(new Adaptr.AvailabilityListener() {
.@Override
public void onPlayerAvailable(AdaptrPlayer AdaptrPlayer) {
// music is available! render access to it
}

.@Override
public void onPlayerUnavailable(Exception e) {
// music is not available!
}
});
}

}

Functions

getPlayerInstance
Link copied to clipboard
fun getPlayerInstance(): AdaptrPlayer

This methods provides a way to get a reference to the singleton FeedAudioPlayer that was created from the initialize() method. This method returns the FeedAudioPlayer instantly irrespective of whether the player is ready or not.

fun getPlayerInstance(listener: AvailabilityListener)

This methods provides a way to get a reference to the AdaptrPlayer that was created from the initialize method, but only once the AdaptrPlayer has determined music is available to the client or not. This method returns the AdaptrPlayer via the AvailabilityListener to emphasize that that the player is not useful until the Adaptr servers are contacted and music is deemed available to this client.

initialize
Link copied to clipboard
fun initialize(builder: AdaptrPlayer.Builder)

Create a singleton AdaptrPlayer instance using the provided AdaptrPlayer.Builder and trigger an asynchronous request to the Adaptr servers for the list of available music stations. Only a single call should be made to this in the app lifetime.

fun initialize(context: Context, token: String, secret: String)

initalize the Adaptr service