diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-12-08 13:42:11 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-12-08 13:42:11 -0800 |
commit | 57987e4843b45303f5adf7438e6c38390156a479 (patch) | |
tree | 71a2ed2d73654233308a4a903cc3e14693b1c363 /subsonic-android | |
parent | a46564fa65d1cdf304bf8e84553efc0686066b75 (diff) | |
download | dsub-57987e4843b45303f5adf7438e6c38390156a479.tar.gz dsub-57987e4843b45303f5adf7438e6c38390156a479.tar.bz2 dsub-57987e4843b45303f5adf7438e6c38390156a479.zip |
Only run position cacher when playing
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; |