aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-12-07 19:48:09 -0800
committerScott Jackson <daneren2005@gmail.com>2012-12-07 19:48:09 -0800
commitaca5b2838dc622ced1af6c0903d50cc208c83c2f (patch)
tree265148f10835cf319e3fa43f0c7286fa720735da /subsonic-android
parent91779a48dcfde020feac716df5666cdecd7a9c06 (diff)
downloaddsub-aca5b2838dc622ced1af6c0903d50cc208c83c2f.tar.gz
dsub-aca5b2838dc622ced1af6c0903d50cc208c83c2f.tar.bz2
dsub-aca5b2838dc622ced1af6c0903d50cc208c83c2f.zip
Made cachedPosition update in download service instead of when download activity is active
Diffstat (limited to 'subsonic-android')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java27
1 files changed, 23 insertions, 4 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index 9a4ad899..5f709b91 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -60,6 +60,9 @@ import android.os.IBinder;
import android.os.PowerManager;
import android.util.Log;
import github.daneren2005.dsub.activity.SubsonicTabActivity;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
/**
* @author Sindre Mehus
@@ -109,6 +112,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private VisualizerController visualizerController;
private boolean showVisualization;
private boolean jukeboxEnabled;
+ private ScheduledExecutorService executorService;
private Timer sleepTimer;
private int timerDuration;
@@ -186,6 +190,23 @@ 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
@@ -682,11 +703,9 @@ public class DownloadServiceImpl extends Service implements DownloadService {
return 0;
}
if (jukeboxEnabled) {
- cachedPosition = jukeboxService.getPositionSeconds() * 1000;
- return cachedPosition;
+ return jukeboxService.getPositionSeconds() * 1000;
} else {
- cachedPosition = mediaPlayer.getCurrentPosition();
- return cachedPosition;
+ return mediaPlayer.getCurrentPosition();
}
} catch (Exception x) {
handleError(x);