diff options
Diffstat (limited to 'subsonic-android')
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 5f709b91..929c22c7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -190,23 +190,6 @@ public class DownloadServiceImpl extends Service implements DownloadService { instance = this; lifecycleSupport.onCreate(); - - final Handler updateHandler = new Handler(); - Runnable runnable = new Runnable() { - @Override - public void run() { - updateHandler.post(new Runnable() { - @Override - public void run() { - if(mediaPlayer != null && playerState == PlayerState.STARTED) { - cachedPosition = mediaPlayer.getCurrentPosition(); - } - } - }); - } - }; - executorService = Executors.newSingleThreadScheduledExecutor(); - executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS); } @Override @@ -761,6 +744,28 @@ public class DownloadServiceImpl extends Service implements DownloadService { } else if (playerState == COMPLETED) { scrobbler.scrobble(this, currentPlaying, true); } + + if(playerState == STARTED) { + Runnable runnable = new Runnable() { + @Override + public void run() { + handler.post(new Runnable() { + @Override + public void run() { + if(mediaPlayer != null) { + cachedPosition = mediaPlayer.getCurrentPosition(); + } + } + }); + } + }; + executorService = Executors.newSingleThreadScheduledExecutor(); + executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS); + } else { + if(executorService != null && !executorService.isShutdown()) { + executorService.shutdown(); + } + } } @Override @@ -841,6 +846,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { // If file is not completely downloaded, restart the playback from the current position. int pos = mediaPlayer.getCurrentPosition(); + Log.d(TAG, pos + " of " + cachedPosition); if(pos == 0) { Log.w(TAG, "Using cached current position"); pos = cachedPosition; |