From 3c95288c04dbf79bcd27f8b3515c23013876f48e Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 20 Nov 2014 15:28:37 -0800 Subject: L on Nexus 5 jump position later instead of immediately like KK --- .../daneren2005/dsub/service/DownloadService.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 691a32b2..cee2c456 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -1187,7 +1187,16 @@ public class DownloadService extends Service { while(isRunning) { try { if(mediaPlayer != null && playerState == STARTED) { - cachedPosition = mediaPlayer.getCurrentPosition(); + int newPosition = mediaPlayer.getCurrentPosition(); + + // If sudden jump in position, something is wrong + if(subtractNextPosition == 0 && newPosition > (cachedPosition + 5000)) { + // Only 1 second should have gone by, subtract the rest + subtractPosition += (newPosition - cachedPosition) - 1000; + } + + cachedPosition = newPosition; + if(subtractNextPosition > 0) { // Subtraction amount is current position - how long ago onCompletionListener was called subtractPosition = cachedPosition - (int) (System.currentTimeMillis() - subtractNextPosition); @@ -1226,7 +1235,7 @@ public class DownloadService extends Service { public void setSuggestedPlaylistName(String name, String id) { this.suggestedPlaylistName = name; this.suggestedPlaylistId = id; - + SharedPreferences.Editor editor = Util.getPreferences(this).edit(); editor.putString(Constants.PREFERENCES_KEY_PLAYLIST_NAME, name); editor.putString(Constants.PREFERENCES_KEY_PLAYLIST_ID, id); @@ -1276,7 +1285,7 @@ public class DownloadService extends Service { // Don't try again, just resetup media player and continue on controller = null; } - + // Restart from same position and state we left off in play(getCurrentPlayingIndex(), false, pos); } @@ -1505,7 +1514,7 @@ public class DownloadService extends Service { if (start || autoPlayStart) { mediaPlayer.start(); setPlayerState(STARTED); - + // Disable autoPlayStart after done autoPlayStart = false; } else { -- cgit v1.2.3