private synchronized void checkShufflePlay() { final int listSize = 20; boolean wasEmpty = downloadList.isEmpty(); long revisionBefore = revision; // First, ensure that list is at least 20 songs long. int size = size(); if (size < listSize) { for (MusicDirectory.Entry song : shufflePlayBuffer.get(listSize - size)) { DownloadFile downloadFile = new DownloadFile(this, song); downloadList.add(downloadFile); revision++; } } int currIndex = currentPlaying == null ? 0 : getCurrentPlayingIndex(); // Only shift playlist if playing song #5 or later. if (currIndex > 4) { int songsToShift = currIndex - 2; for (MusicDirectory.Entry song : shufflePlayBuffer.get(songsToShift)) { downloadList.add(new DownloadFile(this, song)); downloadList.get(0).cancelDownload(); downloadList.remove(0); revision++; } } if (revisionBefore != revision) { updateJukeboxPlaylist(); } if (wasEmpty && !downloadList.isEmpty()) { play(0); } }
@Override public void onDestroy() { super.onDestroy(); lifecycleSupport.onDestroy(); mediaPlayer.release(); shufflePlayBuffer.shutdown(); if (equalizerController != null) { equalizerController.release(); } if (visualizerController != null) { visualizerController.release(); } instance = null; }