diff options
Diffstat (limited to 'subsonic-android/src')
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java | 2 | ||||
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 45 |
2 files changed, 29 insertions, 18 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index 7c5c9513..735bf98f 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -512,7 +512,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi protected void onPause() { super.onPause(); executorService.shutdown(); - if (visualizerView != null) { + if (visualizerView != null && visualizerView.isActive()) { visualizerView.setActive(false); } } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 114edd1d..bf68e905 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -120,7 +120,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { private VisualizerController visualizerController; private boolean showVisualization; private boolean jukeboxEnabled; - private ScheduledExecutorService executorService; + private PositionCache positionCache; private StreamProxy proxy; private Timer sleepTimer; @@ -836,27 +836,38 @@ public class DownloadServiceImpl extends Service implements DownloadService { scrobbler.scrobble(this, currentPlaying, true); } - if(playerState == STARTED && (executorService == null || executorService.isShutdown())) { - Runnable runnable = new Runnable() { - @Override - public void run() { + if(playerState == STARTED && positionCache == null) { + positionCache = new PositionCache(); + Thread thread = new Thread(positionCache); + thread.start(); + } else if(playerState != STARTED && positionCache != null) { + positionCache.stop(); + positionCache = null; + } + } + + private class PositionCache implements Runnable { + boolean isRunning = true; + + public void stop() { + isRunning = false; + } + + @Override + public void run() { + while(isRunning) { + try { if(mediaPlayer != null && playerState == STARTED) { - try { - cachedPosition = mediaPlayer.getCurrentPosition(); - } catch(Exception e) { - executorService.shutdown(); - } + cachedPosition = mediaPlayer.getCurrentPosition(); } + Thread.sleep(200L); + } + catch(Exception e) { + isRunning = false; } - }; - executorService = Executors.newSingleThreadScheduledExecutor(); - executorService.scheduleWithFixedDelay(runnable, 200L, 200L, TimeUnit.MILLISECONDS); - } else if(playerState != STARTED) { - if(executorService != null && !executorService.isShutdown()) { - executorService.shutdownNow(); } } - } + } private synchronized void setPlayerStateCompleted() { Log.i(TAG, this.playerState.name() + " -> " + PlayerState.COMPLETED + " (" + currentPlaying + ")"); |