diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-02-20 21:10:58 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-02-20 21:10:58 -0800 |
commit | 93c2041111171e223d464bb67da6b331076abe4f (patch) | |
tree | 6f1349c4f1e62350a31a8d877a3f03a6221fc860 | |
parent | ea08c8902fe35320122aa9402af499ae07b586b7 (diff) | |
download | dsub-93c2041111171e223d464bb67da6b331076abe4f.tar.gz dsub-93c2041111171e223d464bb67da6b331076abe4f.tar.bz2 dsub-93c2041111171e223d464bb67da6b331076abe4f.zip |
Use playNext if on partial file but playback is done for it
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 8aee7e3f..901cc1d1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -1030,10 +1030,11 @@ public class DownloadServiceImpl extends Service implements DownloadService { return true; } }); + + final int duration = downloadFile.getSong().getDuration() == null ? 0 : downloadFile.getSong().getDuration() * 1000; mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mediaPlayer) { - // setPlayerState(COMPLETED); setPlayerStateCompleted(); // Acquire a temporary wakelock, since when we return from @@ -1041,7 +1042,9 @@ public class DownloadServiceImpl extends Service implements DownloadService { // and allow the device to go to sleep. wakeLock.acquire(60000); - if (!isPartial) { + int pos = cachedPosition; + Log.i(TAG, "Ending position " + pos + " of " + duration); + if (!isPartial || (downloadFile.isWorkDone() && (Math.abs(duration - pos) < 10000))) { if(nextPlaying != null && nextPlayerState == PlayerState.PREPARED) { playNext(); } else { @@ -1051,22 +1054,14 @@ public class DownloadServiceImpl extends Service implements DownloadService { } // If file is not completely downloaded, restart the playback from the current position. - int pos = cachedPosition; synchronized (DownloadServiceImpl.this) { - int duration = downloadFile.getSong().getDuration() == null ? 0 : downloadFile.getSong().getDuration() * 1000; - Log.i(TAG, "Ending position " + pos + " of " + duration); if(downloadFile.isWorkDone()) { - // Reached the end of the song - if(Math.abs(duration - pos) < 10000) { - onSongCompleted(); // Complete was called early even though file is fully buffered - } else { - Log.i(TAG, "Requesting restart from " + pos + " of " + duration); - reset(); - downloadFile.setPlaying(false); - doPlay(downloadFile, pos, true); - downloadFile.setPlaying(true); - } + Log.i(TAG, "Requesting restart from " + pos + " of " + duration); + reset(); + downloadFile.setPlaying(false); + doPlay(downloadFile, pos, true); + downloadFile.setPlaying(true); } else { Log.i(TAG, "Requesting restart from " + pos + " of " + duration); reset(); @@ -1347,7 +1342,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { } while (!bufferComplete()) { - Util.sleepQuietly(2000L); + Util.sleepQuietly(5000L); if (isCancelled()) { return; } |