private void updateSoundSystemUI() {
   if (playbackInfo.getSong() != null) {
     if (mCurrentSong == null || !playbackInfo.getSong().getUrl().equals(mCurrentSong.getUrl())) {
       mCurrentSong = playbackInfo.getSong();
       String artist =
           mCurrentSong.getArtist().contains("unknown")
               ? "Unknown artist"
               : mCurrentSong.getArtist();
       String album =
           mCurrentSong.getAlbum().contains("unknown") ? "Unknown album" : mCurrentSong.getAlbum();
       mSongAuthor.setVisibility(View.VISIBLE);
       mSongAlbum.setVisibility(View.VISIBLE);
       mSongProgress.setVisibility(View.VISIBLE);
       mSongProgressElapsed.setVisibility(View.VISIBLE);
       mSongProgressLeft.setVisibility(View.VISIBLE);
       mSongAuthor.setText(artist);
       mSongName.setText(mCurrentSong.getTitle());
       mSongAlbum.setText(album);
       mSongProgress.setMax(mCurrentSong.getDuration());
     }
     mSongProgress.setProgress(playbackInfo.getTime());
   } else {
     mCurrentSong = null;
     mSongAuthor.setVisibility(View.INVISIBLE);
     mSongAlbum.setVisibility(View.INVISIBLE);
     mSongProgress.setVisibility(View.INVISIBLE);
     mSongProgressElapsed.setVisibility(View.INVISIBLE);
     mSongProgressLeft.setVisibility(View.INVISIBLE);
     mSongName.setText("No song selected");
   }
   mCurrentActionButton.setBackgroundResource(
       playbackInfo.getStatus() == PlaybackStatus.PAUSED
           ? R.drawable.music_play
           : R.drawable.music_pause);
 }
 private void playPrevious() {
   int index = -1;
   if (mCurrentSong != null) {
     index = mSongUrls.indexOf(mCurrentSong.getUrl());
   }
   index--;
   if (index <= -1) {
     index = mSongUrls.size() - 1;
   }
   String url = mSongUrls.get(index);
   playUrl(url);
 }
 private void playNext() {
   int index = -1;
   if (mCurrentSong != null) {
     index = mSongUrls.indexOf(mCurrentSong.getUrl());
   }
   index++;
   if (index >= mSongUrls.size()) {
     index = 0;
   }
   String url = mSongUrls.get(index);
   playUrl(url);
 }
  private void initPlayList() {
    List<SongInfo> songs = new ArrayList<>();
    mSongMap.clear();
    mSongUrls.clear();
    ContentResolver musicResolver = mActivity.getContentResolver();
    Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
    if (musicCursor != null && musicCursor.moveToFirst()) {
      int albumColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ALBUM);
      int artistColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
      int displayNameColumn =
          musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.DISPLAY_NAME);
      int durationColumn =
          musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.DURATION);
      int titleColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
      int idColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
      do {
        String album = musicCursor.getString(albumColumn);
        String artist = musicCursor.getString(artistColumn);
        String displayName = musicCursor.getString(displayNameColumn);
        long duration = musicCursor.getLong(durationColumn);
        String title = musicCursor.getString(titleColumn);
        long id = musicCursor.getLong(idColumn);

        SongInfo songInfo = new SongInfo();
        songInfo.setAlbum(album);
        songInfo.setArtist(artist);
        songInfo.setDisplayName(displayName);
        songInfo.setDuration((int) duration);
        songInfo.setTitle(title);
        songInfo.setUrl(id + "");
        songs.add(songInfo);
      } while (musicCursor.moveToNext());
    }
    Collections.sort(songs, mSongComparator);
    for (SongInfo song : songs) {
      mSongMap.put(song.getUrl(), song);
      mSongUrls.add(song.getUrl());
    }
  }
 private void togglePlayback() {
   if (playbackInfo.getStatus() == PlaybackStatus.PAUSED) {
     String url = null;
     if (mCurrentSong != null) {
       url = mCurrentSong.getUrl();
     } else {
       url = mSongUrls.get(0);
     }
     playUrl(url);
   } else {
     pause();
   }
 }