Пример #1
0
  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
 @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));
   }
 }