aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-09-15 08:55:45 -0700
committerScott Jackson <daneren2005@gmail.com>2015-09-15 08:55:45 -0700
commit3386851d2a638892942a52ca8493458dfa683871 (patch)
tree394b0bad638bc586e9bed1bc6e37b46779be6861
parentc7f7e1e59981b5c9d492725e92b75ff8d8ddd88f (diff)
downloaddsub-3386851d2a638892942a52ca8493458dfa683871.tar.gz
dsub-3386851d2a638892942a52ca8493458dfa683871.tar.bz2
dsub-3386851d2a638892942a52ca8493458dfa683871.zip
Fix position not updating for remote playback anymore
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java52
1 files changed, 46 insertions, 6 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
index 0db091ad..3f3f036a 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -42,7 +42,6 @@ import github.daneren2005.dsub.domain.RepeatMode;
import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.receiver.MediaButtonIntentReceiver;
import github.daneren2005.dsub.util.ArtistRadioBuffer;
-import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Notifications;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.Constants;
@@ -1284,7 +1283,20 @@ public class DownloadService extends Service {
}
if(playerState == STARTED && positionCache == null && remoteState == LOCAL) {
- positionCache = new PositionCache();
+ positionCache = new LocalPositionCache();
+ Thread thread = new Thread(positionCache, "PositionCache");
+ thread.start();
+ } else if(playerState != STARTED && positionCache != null) {
+ positionCache.stop();
+ positionCache = null;
+ }
+
+ if(playerState == STARTED && positionCache == null) {
+ if(remoteState == LOCAL) {
+ positionCache = new LocalPositionCache();
+ } else {
+ positionCache = new PositionCache();
+ }
Thread thread = new Thread(positionCache, "PositionCache");
thread.start();
} else if(playerState != STARTED && positionCache != null) {
@@ -1306,6 +1318,28 @@ public class DownloadService extends Service {
// Stop checking position before the song reaches completion
while(isRunning) {
try {
+ onSongProgress();
+ Thread.sleep(1000L);
+ }
+ catch(Exception e) {
+ isRunning = false;
+ positionCache = null;
+ }
+ }
+ }
+ }
+ private class LocalPositionCache extends PositionCache {
+ boolean isRunning = true;
+
+ public void stop() {
+ isRunning = false;
+ }
+
+ @Override
+ public void run() {
+ // Stop checking position before the song reaches completion
+ while(isRunning) {
+ try {
if(mediaPlayer != null && playerState == STARTED) {
int newPosition = mediaPlayer.getCurrentPosition();
@@ -2372,9 +2406,14 @@ public class DownloadService extends Service {
}
if(run) {
- onSongsChanged();
- onSongProgress();
- onStateUpdate();
+ mediaPlayerHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ onSongsChanged();
+ onSongProgress();
+ onStateUpdate();
+ }
+ });
}
}
public void removeOnSongChangeListener(OnSongChangedListener listener) {
@@ -2418,12 +2457,13 @@ public class DownloadService extends Service {
final long atRevision = revision;
final Integer duration = getPlayerDuration();
final boolean isSeekable = isSeekable();
+ final int position = getPlayerPosition();
for(final OnSongChangedListener listener: onSongChangedListeners) {
handler.post(new Runnable() {
@Override
public void run() {
if(revision == atRevision) {
- listener.onSongProgress(currentPlaying, cachedPosition, duration, isSeekable);
+ listener.onSongProgress(currentPlaying, position, duration, isSeekable);
}
}
});