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:
_10CallResult<PlayerState> playerStateCall = playerApi.getPlayerState();_10Result<PlayerState> playerStateResult = playerStateCall.await(10, TimeUnit.SECONDS);_10if (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:
_10playerApi.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:
_10playerApi.subscribeToPlayerState()_10 .setEventCallback(playerState -> {_10 // the Spotify App keeps you updated on PlayerState with this event_10 })_10 .setErrorCallback(throwable -> {_10 // =( =( =(_10 });