Example #1
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   /*
      Test To See if The Result is coming from the login Activity
   */
   if (requestCode == LOGIN_REQUEST_CODE) {
     AuthenticationResponse authenticationResponse =
         AuthenticationClient.getResponse(resultCode, data);
     /*
        If a token is returned, the user logged in and we can now Initialize the Player.
     */
     if (authenticationResponse.getType() == AuthenticationResponse.Type.TOKEN) {
       /*
          Store Access Token in Shared Preferences
       */
       SharedPreferences sharedPreferences = getSharedPreferences(SESSION_PREFS, MODE_PRIVATE);
       SharedPreferences.Editor editor = sharedPreferences.edit();
       editor.putString(LAST_VALID_SESSION_TOKEN, authenticationResponse.getAccessToken());
       editor.commit();
       /*
          Initialize Player
       */
       PlayerUtils.init(this, authenticationResponse.getAccessToken());
     }
     /*
        If Login does not Return Token.... Try Again
     */
     else {
       LoginManager.startLoginActivity(this, LOGIN_REQUEST_CODE);
     }
   }
 }
Example #2
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    // Check if result comes from the correct activity
    if (requestCode == REQUEST_CODE) {
      AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);

      if (response.getType() == AuthenticationResponse.Type.TOKEN) {
        Config playerConfig = new Config(this, response.getAccessToken(), CLIENT_ID);
        mPlayer =
            Spotify.getPlayer(
                playerConfig,
                this,
                new Player.InitializationObserver() {
                  @Override
                  public void onInitialized(Player player) {
                    // Default song shoreline
                    Log.w("Initialized", "Init");
                    mPlayer.addConnectionStateCallback(MainActivity.this);
                    mPlayer.addPlayerNotificationCallback(MainActivity.this);
                    mPlayer.play("spotify:track:2nK30KDjrDHRedyIcHTOQS");
                  }

                  @Override
                  public void onError(Throwable throwable) {
                    Log.e("MainActivity", "Could not initialize player: " + throwable.getMessage());
                  }
                });
      }
    }
  }
Example #3
0
  private void openLoginWindow() {
    final AuthenticationRequest request =
        new AuthenticationRequest.Builder(
                CLIENT_ID, AuthenticationResponse.Type.TOKEN, REDIRECT_URI)
            .setScopes(
                new String[] {
                  "user-read-private", "playlist-read", "playlist-read-private", "streaming"
                })
            .build();

    AuthenticationClient.openLoginActivity(this, REQUEST_CODE, request);
  }
Example #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AuthenticationRequest.Builder builder =
        new AuthenticationRequest.Builder(
            CLIENT_ID, AuthenticationResponse.Type.TOKEN, REDIRECT_URI);

    builder.setScopes(new String[] {"user-read-private", "streaming"});
    AuthenticationRequest request = builder.build();

    AuthenticationClient.openLoginActivity(this, REQUEST_CODE, request);

    findViewById(R.id.gotoAlarm)
        .setOnClickListener(
            new View.OnClickListener() {
              public void onClick(View v) {
                gotoAlarm();
              }
            });
  }
Example #5
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    // Check if result comes from the correct activity
    if (requestCode == REQUEST_CODE) {
      AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);
      switch (response.getType()) {
          // Response was successful and contains auth token
        case TOKEN:
          onAuthenticationComplete(response);
          break;

          // Auth flow returned an error
        case ERROR:
          logStatus("Auth error: " + response.getError());
          break;

          // Most likely auth flow was cancelled
        default:
          logStatus("Auth result: " + response.getType());
      }
    }
  }