From 93c2041111171e223d464bb67da6b331076abe4f Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 20 Feb 2013 21:10:58 -0800 Subject: Use playNext if on partial file but playback is done for it --- .../dsub/service/DownloadServiceImpl.java | 27 +++++++++------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'subsonic-android/src') 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; } -- cgit v1.2.3