diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-12-15 18:05:32 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-12-15 18:05:32 -0800 |
commit | 98d2d7ad9dcfaa4791fd59e81c4c74faad691ad9 (patch) | |
tree | 511b35531cc4122933e342589b2e618436259ff4 /src | |
parent | 087a7dd150d7f0180e92c47e5a43adfbd8aa91c4 (diff) | |
download | dsub-98d2d7ad9dcfaa4791fd59e81c4c74faad691ad9.tar.gz dsub-98d2d7ad9dcfaa4791fd59e81c4c74faad691ad9.tar.bz2 dsub-98d2d7ad9dcfaa4791fd59e81c4c74faad691ad9.zip |
#430 Fix caching not working while casting
Diffstat (limited to 'src')
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadService.java | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index c4dd3546..87144402 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -28,6 +28,7 @@ import static github.daneren2005.dsub.domain.PlayerState.PREPARED; import static github.daneren2005.dsub.domain.PlayerState.PREPARING; import static github.daneren2005.dsub.domain.PlayerState.STARTED; import static github.daneren2005.dsub.domain.PlayerState.STOPPED; +import static github.daneren2005.dsub.domain.RemoteControlState.LOCAL; import github.daneren2005.dsub.R; import github.daneren2005.dsub.audiofx.AudioEffectsController; @@ -142,7 +143,7 @@ public class DownloadService extends Service { private float volume = 1.0f; private AudioEffectsController effectsController; - private RemoteControlState remoteState = RemoteControlState.LOCAL; + private RemoteControlState remoteState = LOCAL; private PositionCache positionCache; private BufferProxy proxy; @@ -400,7 +401,7 @@ public class DownloadService extends Service { } private void updateJukeboxPlaylist() { - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { remoteController.updatePlaylist(); } } @@ -408,7 +409,7 @@ public class DownloadService extends Service { public synchronized void restore(List<MusicDirectory.Entry> songs, List<MusicDirectory.Entry> toDelete, int currentPlayingIndex, int currentPlayingPosition) { SharedPreferences prefs = Util.getPreferences(this); remoteState = RemoteControlState.values()[prefs.getInt(Constants.PREFERENCES_KEY_CONTROL_MODE, 0)]; - if(remoteState != RemoteControlState.LOCAL) { + if(remoteState != LOCAL) { String id = prefs.getString(Constants.PREFERENCES_KEY_CONTROL_ID, null); setRemoteState(remoteState, null, id); } @@ -822,10 +823,10 @@ public class DownloadService extends Service { nextPlayingTask = null; } setCurrentPlaying(index, start); - if (start && remoteState != RemoteControlState.LOCAL) { + if (start && remoteState != LOCAL) { remoteController.changeTrack(index, currentPlaying); } - if (remoteState == RemoteControlState.LOCAL) { + if (remoteState == LOCAL) { bufferAndPlay(position, start); checkDownloads(); setNextPlaying(); @@ -894,7 +895,7 @@ public class DownloadService extends Service { } try { - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { remoteController.changePosition(position / 1000); } else { mediaPlayer.seekTo(position); @@ -983,7 +984,7 @@ public class DownloadService extends Service { public synchronized void pause(boolean temp) { try { if (playerState == STARTED) { - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { remoteController.stop(); } else { mediaPlayer.pause(); @@ -1000,7 +1001,7 @@ public class DownloadService extends Service { public synchronized void stop() { try { if (playerState == STARTED) { - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { remoteController.stop(); setPlayerState(STOPPED); handler.post(new Runnable() { @@ -1023,7 +1024,7 @@ public class DownloadService extends Service { public synchronized void start() { try { - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { remoteController.start(); } else { // Only start if done preparing @@ -1047,7 +1048,7 @@ public class DownloadService extends Service { } try { // Only set to idle if it's not being killed to start RemoteController - if(remoteState == RemoteControlState.LOCAL) { + if(remoteState == LOCAL) { setPlayerState(IDLE); } mediaPlayer.setOnErrorListener(null); @@ -1087,7 +1088,7 @@ public class DownloadService extends Service { if (playerState == IDLE || playerState == DOWNLOADING || playerState == PREPARING) { return 0; } - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { return remoteController.getRemotePosition() * 1000; } else { return Math.max(0, cachedPosition - subtractPosition); @@ -1106,7 +1107,7 @@ public class DownloadService extends Service { } } if (playerState != IDLE && playerState != DOWNLOADING && playerState != PlayerState.PREPARING) { - if(remoteState == RemoteControlState.LOCAL) { + if(remoteState == LOCAL) { try { return mediaPlayer.getDuration(); } catch (Exception x) { @@ -1163,7 +1164,7 @@ public class DownloadService extends Service { scrobbler.scrobble(this, currentPlaying, true); } - if(playerState == STARTED && positionCache == null && remoteState == RemoteControlState.LOCAL) { + if(playerState == STARTED && positionCache == null && remoteState == LOCAL) { positionCache = new PositionCache(); Thread thread = new Thread(positionCache, "PositionCache"); thread.start(); @@ -1297,7 +1298,7 @@ public class DownloadService extends Service { } public boolean isRemoteEnabled() { - return remoteState != RemoteControlState.LOCAL; + return remoteState != LOCAL; } public RemoteController getRemoteController() { @@ -1333,7 +1334,7 @@ public class DownloadService extends Service { remoteController.shutdown(); remoteController = null; - if(newState == RemoteControlState.LOCAL) { + if(newState == LOCAL) { mediaRouter.setDefaultRoute(); } } @@ -1345,7 +1346,7 @@ public class DownloadService extends Service { break; case CHROMECAST: if(ref == null) { - remoteState = RemoteControlState.LOCAL; + remoteState = LOCAL; break; } remoteController = (RemoteController) ref; @@ -1360,7 +1361,7 @@ public class DownloadService extends Service { play(getCurrentPlayingIndex(), isPlaying, position); } - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { reset(); // Cancel current download, if necessary. @@ -1379,7 +1380,7 @@ public class DownloadService extends Service { } } - if(remoteState == RemoteControlState.LOCAL) { + if(remoteState == LOCAL) { checkDownloads(); } @@ -1389,7 +1390,7 @@ public class DownloadService extends Service { public void run() { RouteInfo info = mediaRouter.getRouteForId(routeId); if(info == null) { - setRemoteState(RemoteControlState.LOCAL, null); + setRemoteState(LOCAL, null); } else if(newState == RemoteControlState.CHROMECAST) { RemoteController controller = mediaRouter.getRemoteController(info); if(controller != null) { @@ -1545,7 +1546,7 @@ public class DownloadService extends Service { resetNext(); // Exit when using remote controllers - if(remoteState != RemoteControlState.LOCAL) { + if(remoteState != LOCAL) { return; } @@ -1713,7 +1714,7 @@ public class DownloadService extends Service { DownloadFile movedSong = list.remove(from); list.add(to, movedSong); currentPlayingIndex = downloadList.indexOf(currentPlaying); - if(remoteState != RemoteControlState.LOCAL && mainList) { + if(remoteState != LOCAL && mainList) { updateJukeboxPlaylist(); } else if(mainList && (movedSong == nextPlaying || movedSong == currentPlaying || (currentPlayingIndex + 1) == to)) { // Moving next playing, current playing, or moving a song to be next playing @@ -1760,7 +1761,7 @@ public class DownloadService extends Service { checkShufflePlay(); } - if (remoteState != RemoteControlState.LOCAL || !Util.isNetworkConnected(this, true) || Util.isOffline(this)) { + if (!Util.isNetworkConnected(this, true) || Util.isOffline(this)) { return; } @@ -1768,8 +1769,8 @@ public class DownloadService extends Service { return; } - // Need to download current playing? - if (currentPlaying != null && currentPlaying != currentDownloading && !currentPlaying.isWorkDone()) { + // Need to download current playing and not casting? + if (currentPlaying != null && remoteState == LOCAL && currentPlaying != currentDownloading && !currentPlaying.isWorkDone()) { // Cancel current download, if necessary. if (currentDownloading != null) { currentDownloading.cancelDownload(); @@ -1781,13 +1782,13 @@ public class DownloadService extends Service { } // Find a suitable target for download. - else if (currentDownloading == null || currentDownloading.isWorkDone() || currentDownloading.isFailed() && (!downloadList.isEmpty() || !backgroundDownloadList.isEmpty())) { + else if (currentDownloading == null || currentDownloading.isWorkDone() || currentDownloading.isFailed() && ((!downloadList.isEmpty() && remoteState == LOCAL) || !backgroundDownloadList.isEmpty())) { currentDownloading = null; int n = size(); int preloaded = 0; - if(n != 0) { + if(n != 0 && remoteState == LOCAL) { int start = currentPlaying == null ? 0 : getCurrentPlayingIndex(); if(start == -1) { start = 0; @@ -1813,7 +1814,7 @@ public class DownloadService extends Service { } while (i != start); } - if((preloaded + 1 == n || preloaded >= Util.getPreloadCount(this) || downloadList.isEmpty()) && !backgroundDownloadList.isEmpty()) { + if((preloaded + 1 == n || preloaded >= Util.getPreloadCount(this) || downloadList.isEmpty() || remoteState != LOCAL) && !backgroundDownloadList.isEmpty()) { for(int i = 0; i < backgroundDownloadList.size(); i++) { DownloadFile downloadFile = backgroundDownloadList.get(i); if(downloadFile.isWorkDone() && (!downloadFile.shouldSave() || downloadFile.isSaved()) || downloadFile.isFailedMax()) { |