本文整理汇总了Java中com.spotify.sdk.android.player.Spotify类的典型用法代码示例。如果您正苦于以下问题:Java Spotify类的具体用法?Java Spotify怎么用?Java Spotify使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Spotify类属于com.spotify.sdk.android.player包,在下文中一共展示了Spotify类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAuthenticationComplete
import com.spotify.sdk.android.player.Spotify; //导入依赖的package包/类
private void onAuthenticationComplete(AuthenticationResponse authResponse, String clientID) {
Log.d("DEBUG", "Got authentication token");
if (mPlayer == null) {
Config playerConfig = new Config(this, authResponse.getAccessToken(), clientID);
mPlayer = Spotify.getPlayer(playerConfig, this, new SpotifyPlayer.InitializationObserver() {
@Override
public void onInitialized(SpotifyPlayer player) {
Log.d("DEBUG", "-- Player initialized --");
mPlayer
.setConnectivityStatus(mOperationCallback, getNetworkConnectivity(MainActivity.this));
mPlayer.addNotificationCallback(MainActivity.this);
mPlayer.addConnectionStateCallback(MainActivity.this);
}
@Override
public void onError(Throwable error) {
Log.d("DEBUG", "Error in initialization: " + error.getMessage());
}
});
} else {
mPlayer.login(authResponse.getAccessToken());
}
}
示例2: initializePlayer
import com.spotify.sdk.android.player.Spotify; //导入依赖的package包/类
private void initializePlayer() {
SharedPreferences prefsAppData = getSharedPreferences(getString(R.string.sharedpreferences_global), Context.MODE_PRIVATE);
if (prefsAppData.getInt(getString(R.string.responseType), -1) == AuthenticationResponse.Type.TOKEN.ordinal()) {
Config config = new Config(
this,
prefsAppData.getString(getString(R.string.spotifyAccessToken_value), null),
prefsAppData.getString(getString(R.string.clientId), null)
);
spotifyPlayer = Spotify.getPlayer(config, this, new Player.InitializationObserver() {
@Override
public void onInitialized(Player player) {
player.addConnectionStateCallback(MainActivity.connectionStateCallback);
player.addPlayerNotificationCallback(TracksActivity.this);
}
@Override
public void onError(Throwable throwable) {
Log.e("PLAYER", "ERROR: " + throwable.getMessage());
}
});
}
}
示例3: startPlayer
import com.spotify.sdk.android.player.Spotify; //导入依赖的package包/类
/***
* @param context
* @param token : Spotify token needed to use the api
* @param observer : used to know when player is ready
* @param playerNotificationCallback
* @param connectionStateCallback
*/
public static void startPlayer(final Context context, String token, final Player.InitializationObserver observer, @Nullable final PlayerNotificationCallback playerNotificationCallback, @Nullable final ConnectionStateCallback connectionStateCallback) {
SpotifyPlayerManager.context = context;
Config playerConfig = new Config(context, token, SpotifyManager.API_KEY);
setConnectionStateCallback(connectionStateCallback);
setPlayerNotificationCallback(playerNotificationCallback);
Spotify.getPlayer(playerConfig, context, new Player.InitializationObserver() {
@Override
public void onInitialized(Player pl) {
player = pl;
if (connectionStateCallback != null)
player.addConnectionStateCallback(SpotifyManager.connectionStateCallback);
if (playerNotificationCallback != null)
player.addPlayerNotificationCallback(SpotifyManager.playerNotificationCallback);
observer.onInitialized(player);
}
@Override
public void onError(Throwable throwable) {
Log.e(SpotifyManager.class.getSimpleName(), "Could not initialize player: " + throwable.getMessage());
observer.onError(throwable);
}
});
}
示例4: startSpotifySession
import com.spotify.sdk.android.player.Spotify; //导入依赖的package包/类
public void startSpotifySession(final Activity activity, String accessToken, final Runnable onStarted, final Runnable onFailed) {
// Spotify API
SpotifyApi api = new SpotifyApi();
api.setAccessToken(accessToken);
mSpotifyService = api.getService();
// Spotify Player Controller
String clientId = getString(R.string.spotify_client_id);
Config playerConfig = new Config(this, accessToken, clientId);
Player player = Spotify.getPlayer(playerConfig, this, null);
mSpotifyPlayerController = new SpotifyPlayerController(player, mSpotifyService);
mSpotifyService.getMe(new Callback<UserPrivate>() {
@Override
public void success(UserPrivate user, Response response) {
saveCurrentUser(user);
activity.runOnUiThread(onStarted);
}
@Override
public void failure(RetrofitError error) {
activity.runOnUiThread(onFailed);
}
});
}
示例5: onDestroy
import com.spotify.sdk.android.player.Spotify; //导入依赖的package包/类
@Override
protected void onDestroy() {
Spotify.destroyPlayer(this);
super.onDestroy();
}
示例6: destroy
import com.spotify.sdk.android.player.Spotify; //导入依赖的package包/类
/***
* Destroy the SpotifyPlayer
*/
public static void destroy() {
Spotify.destroyPlayer(context);
}
示例7: initPlayer
import com.spotify.sdk.android.player.Spotify; //导入依赖的package包/类
private Single<Boolean> initPlayer() {
return Single.create(subscriber -> {
playerConfig = new Config(SpotiqHostService.this,
spotifyCommunicatorService.getAuthenticator().getAccessToken(),
BuildConfig.SPOTIFY_CLIENT_ID);
playerConfig.useCache(false);
spotifyPlayer = Spotify.getPlayer(playerConfig, SpotiqHostService.this, new SpotifyPlayer.InitializationObserver() {
@Override
public void onInitialized(SpotifyPlayer player) {
spotifyPlayer.addConnectionStateCallback(SpotiqHostService.this);
spotifyPlayer.addNotificationCallback(SpotiqHostService.this);
spotifyPlayer.setPlaybackBitrate(new Player.OperationCallback() {
@Override
public void onSuccess() {
subscriber.onSuccess(true);
Log.d(LogTag.LOG_HOST_SERVICE, "Set Spotify Player custom playback bitrate successfully");
sendPlayingStatusBroadcast(false); //make sure all listeners are up to sync with an inititally paused status
mediaSessionHandler.setSessionActive();
}
@Override
public void onError(Error error) {
subscriber.onError(new PlayerInitializationException(error.name()));
Log.d(LogTag.LOG_HOST_SERVICE, "Failed to set Spotify Player playback bitrate. Cause: " + error.toString());
}
}, PlaybackBitrate.BITRATE_HIGH);
}
@Override
public void onError(Throwable throwable) {
subscriber.onError(throwable);
Log.d(LogTag.LOG_HOST_SERVICE, "Could not initialize Spotify Player: " + throwable.getMessage());
stopSelf();
}
});
});
}
示例8: terminate
import com.spotify.sdk.android.player.Spotify; //导入依赖的package包/类
public void terminate() {
mediaSessionController.stopNowPlayingSession();
Spotify.destroyPlayer(mPlayer);
}