Skip to content

Making Remote Calls
Beta

This guide explains how to make remote calls from your app to the Spotify app with the App Remote SDK.

When you make a call via any of the APIs you receive an instance of a CallResult<T> object. CallResult<T> lets you receive results both asynchronously or synchronously. Lets take a look at the example of a synchronous call:


_10
CallResult<PlayerState> playerStateCall = playerApi.getPlayerState();
_10
Result<PlayerState> playerStateResult = playerStateCall.await(10, TimeUnit.SECONDS);
_10
if (playerStateResult.isSuccessful()) {
_10
PlayerState playerState = playerStateResult.getData();
_10
// have some fun with playerState
_10
} else {
_10
Throwable error = playerStateResult.getError();
_10
// try to have some fun with the error
_10
}

And the preferable async way to do the same thing:


_10
playerApi.getPlayerState()
_10
.setResultCallback(playerState -> {
_10
// have fun with playerState
_10
})
_10
.setErrorCallback(throwable -> {
_10
// =(
_10
});

As a result of subscription you receive a Subscription<T> object. For example:


_10
playerApi.subscribeToPlayerState()
_10
.setEventCallback(playerState -> {
_10
// the Spotify App keeps you updated on PlayerState with this event
_10
})
_10
.setErrorCallback(throwable -> {
_10
// =( =( =(
_10
});