コード例 #1
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
  public void onPlayButtonClicked(View view) {
    if (view.getId() == R.id.play_album_button) {
      logStatus("Starting playback the list of tracks");
      mPlayer.play(TEST_ALBUM_TRACKS);
    } else {
      String uri;
      switch (view.getId()) {
        case R.id.play_track_button:
          uri = TEST_SONG_URI;
          break;
        case R.id.play_mono_track_button:
          uri = TEST_SONG_MONO_URI;
          break;
        case R.id.play_48khz_track_button:
          uri = TEST_SONG_48kHz_URI;
          break;
        case R.id.play_playlist_button:
          uri = TEST_PLAYLIST_URI;
          break;
        default:
          throw new IllegalArgumentException("View ID does not have an associated URI to play");
      }

      logStatus("Starting playback for " + uri);
      mPlayer.play(uri);
    }
  }
コード例 #2
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onPauseButtonClicked(View view) {
   if (mCurrentPlayerState.playing) {
     mPlayer.pause();
   } else {
     mPlayer.resume();
   }
 }
コード例 #3
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
  @Override
  protected void onResume() {
    super.onResume();

    // Set up the broadcast receiver for network events. Note that we also unregister
    // this receiver again in onPause().
    mNetworkStateReceiver =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            if (mPlayer != null) {
              Connectivity connectivity = getNetworkConnectivity(getBaseContext());
              logStatus("Network state changed: " + connectivity.toString());
              mPlayer.setConnectivityStatus(connectivity);
            }
          }
        };

    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mNetworkStateReceiver, filter);

    if (mPlayer != null) {
      mPlayer.addPlayerNotificationCallback(DemoActivity.this);
      mPlayer.addConnectionStateCallback(DemoActivity.this);
    }
  }
コード例 #4
0
ファイル: MainActivity.java プロジェクト: jrmeza514/Vibrato
 @Override
 public void onClick(View view) {
   if (mPlayer != null && mPlayer.isInitialized() && mPlayer.isLoggedIn()) {
     if (mPlayerStatusTask.getStatus().equals(AsyncTask.Status.PENDING)) {
       mPlayerStatusTask.execute();
     }
     mPlayer.getPlayerState(playPauseButtonPressedPlayerStateCallback);
   }
 }
コード例 #5
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
  @Override
  protected void onPause() {
    super.onPause();
    unregisterReceiver(mNetworkStateReceiver);

    // Note that calling Spotify.destroyPlayer() will also remove any callbacks on whatever
    // instance was passed as the refcounted owner. So in the case of this particular example,
    // it's not strictly necessary to call these methods, however it is generally good practice
    // and also will prevent your application from doing extra work in the background when
    // paused.
    if (mPlayer != null) {
      mPlayer.removePlayerNotificationCallback(DemoActivity.this);
      mPlayer.removeConnectionStateCallback(DemoActivity.this);
    }
  }
コード例 #6
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
  private void onAuthenticationComplete(AuthenticationResponse authResponse) {
    // Once we have obtained an authorization token, we can proceed with creating a Player.
    logStatus("Got authentication token");
    if (mPlayer == null) {
      Config playerConfig =
          new Config(getApplicationContext(), authResponse.getAccessToken(), CLIENT_ID);
      // Since the Player is a static singleton owned by the Spotify class, we pass "this" as
      // the second argument in order to refcount it properly. Note that the method
      // Spotify.destroyPlayer() also takes an Object argument, which must be the same as the
      // one passed in here. If you pass different instances to Spotify.getPlayer() and
      // Spotify.destroyPlayer(), that will definitely result in resource leaks.
      mPlayer =
          Spotify.getPlayer(
              playerConfig,
              this,
              new Player.InitializationObserver() {
                @Override
                public void onInitialized(Player player) {
                  logStatus("-- Player initialized --");
                  mPlayer.setConnectivityStatus(getNetworkConnectivity(DemoActivity.this));
                  mPlayer.addPlayerNotificationCallback(DemoActivity.this);
                  mPlayer.addConnectionStateCallback(DemoActivity.this);
                  // Trigger UI refresh
                  updateButtons();
                }

                @Override
                public void onError(Throwable error) {
                  logStatus("Error in initialization: " + error.getMessage());
                }
              });
    } else {
      mPlayer.login(authResponse.getAccessToken());
    }
  }
コード例 #7
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onLoginButtonClicked(View view) {
   if (!isLoggedIn()) {
     logStatus("Logging in");
     openLoginWindow();
   } else {
     mPlayer.logout();
   }
 }
コード例 #8
0
ファイル: MainActivity.java プロジェクト: jrmeza514/Vibrato
 void updateStatusBar() {
   try {
     mPlayer.getPlayerState(updateStatusBarPlayerStateCallback);
   } catch (Exception e) {
     e.printStackTrace();
     mPlayerStatusTask.cancel(true);
   }
 }
コード例 #9
0
ファイル: MainActivity.java プロジェクト: jrmeza514/Vibrato
  @Override
  protected void onResume() {
    Log.d("DEBUG_JRM", "ONRESUME");
    super.onResume();
    slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
    try {
      if (mPlayer.isInitialized()) {
        mPlayer.getPlayerState(setPlayPauseButtonIconPlayerStateCallback);
        Log.d("DEBUG_JRM", "RESUME PLAYER INIT");
        if (mPlayerStatusTask.getStatus().equals(AsyncTask.Status.PENDING)) {
          Log.d("DEBUG_JRM", "RESUME STAT PENDING");
          mPlayerStatusTask.execute();
        }
      }
    } catch (NullPointerException e) {

    }
  }
コード例 #10
0
ファイル: MainActivity.java プロジェクト: jrmeza514/Vibrato
 @Override
 public void onPlayerState(PlayerState playerState) {
   /*
      Determine Plater State and play, Pause, or resume track
   */
   SharedPreferences playerPreferences = getSharedPreferences(PLAYER_PREFS, MODE_PRIVATE);
   if (playerState.playing) {
     mPlayer.pause();
     playPauseFloatingActionButton.setImageBitmap(
         BitmapFactory.decodeResource(getResources(), R.mipmap.ic_play_arrow_white));
   } else if (playerState.trackUri != null && !playerState.trackUri.equals("")) {
     mPlayer.resume();
     playPauseFloatingActionButton.setImageBitmap(
         BitmapFactory.decodeResource(getResources(), R.mipmap.ic_pause_white));
   } else {
     /*
        TODO: Implement an solution for storing
     */
     String trackUri = "spotify:track:6QPKYGnAW9QozVz2dSWqRg";
     mPlayer.play(trackUri);
     playPauseFloatingActionButton.setImageBitmap(
         BitmapFactory.decodeResource(getResources(), R.mipmap.ic_pause_white));
   }
 }
コード例 #11
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onShowPlayerStateButtonClicked(View view) {
   mPlayer.getPlayerState(
       new PlayerStateCallback() {
         @Override
         public void onPlayerState(PlayerState playerState) {
           logStatus("-- Current player state --");
           logStatus("Playing? " + playerState.playing);
           logStatus("Position: " + playerState.positionInMs + "ms");
           logStatus("Shuffling? " + playerState.shuffling);
           logStatus("Repeating? " + playerState.repeating);
           logStatus("Active device? " + playerState.activeDevice);
           logStatus("Track uri: " + playerState.trackUri);
           logStatus("Track duration: " + playerState.durationInMs);
         }
       });
 }
コード例 #12
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onToggleShuffleButtonClicked(View view) {
   mPlayer.setShuffle(!mCurrentPlayerState.shuffling);
 }
コード例 #13
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 private boolean isLoggedIn() {
   return mPlayer != null && mPlayer.isLoggedIn();
 }
コード例 #14
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onSkipToPreviousButtonClicked(View view) {
   mPlayer.skipToPrevious();
 }
コード例 #15
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onHighBitrateButtonPressed(View view) {
   mPlayer.setPlaybackBitrate(PlaybackBitrate.BITRATE_HIGH);
 }
コード例 #16
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onSkipToNextButtonClicked(View view) {
   mPlayer.skipToNext();
 }
コード例 #17
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onNormalBitrateButtonPressed(View view) {
   mPlayer.setPlaybackBitrate(PlaybackBitrate.BITRATE_NORMAL);
 }
コード例 #18
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onLowBitrateButtonPressed(View view) {
   mPlayer.setPlaybackBitrate(PlaybackBitrate.BITRATE_LOW);
 }
コード例 #19
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onSeekButtonClicked(View view) {
   // Skip to 10 seconds in the current song
   mPlayer.seekToPosition(10000);
 }
コード例 #20
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onToggleRepeatButtonClicked(View view) {
   mPlayer.setRepeat(!mCurrentPlayerState.repeating);
 }
コード例 #21
0
ファイル: DemoActivity.java プロジェクト: liunick/SpotifyApp
 public void onQueueSongButtonClicked(View view) {
   mPlayer.queue(TEST_QUEUE_SONG_URI);
   Toast toast = Toast.makeText(this, R.string.song_queued_toast, Toast.LENGTH_SHORT);
   toast.show();
 }