From 41a0bdc592bd9d81efc958f59db57e0ce7498a5f Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 9 Jun 2013 18:30:35 -0700 Subject: On error, skip to next if within 10 seconds of the end like completion handler --- .../dsub/service/DownloadServiceImpl.java | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'subsonic-android') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 7858ac3a..664754b1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -648,7 +648,18 @@ public class DownloadServiceImpl extends Service implements DownloadService { setNextPlaying(); } } - + private synchronized void playNext() { + if(nextPlaying != null && nextPlayerState == PlayerState.PREPARED) { + if(!nextSetup) { + playNext(true); + } else { + nextSetup = false; + playNext(false); + } + } else { + onSongCompleted(); + } + } private synchronized void playNext(boolean start) { // Swap the media players since nextMediaPlayer is ready to play if(start) { @@ -1135,19 +1146,23 @@ public class DownloadServiceImpl extends Service implements DownloadService { } private void setupHandlers(final DownloadFile downloadFile, final boolean isPartial) { + final int duration = downloadFile.getSong().getDuration() == null ? 0 : downloadFile.getSong().getDuration() * 1000; mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { public boolean onError(MediaPlayer mediaPlayer, int what, int extra) { Log.w(TAG, "Error on playing file " + "(" + what + ", " + extra + "): " + downloadFile); int pos = cachedPosition; reset(); - downloadFile.setPlaying(false); - doPlay(downloadFile, pos, true); - downloadFile.setPlaying(true); + if (!isPartial || (downloadFile.isWorkDone() && (Math.abs(duration - pos) < 10000))) { + playNext(); + } else { + downloadFile.setPlaying(false); + doPlay(downloadFile, pos, true); + downloadFile.setPlaying(true); + } 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) { @@ -1161,16 +1176,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { 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) { - if(!nextSetup) { - playNext(true); - } else { - nextSetup = false; - playNext(false); - } - } else { - onSongCompleted(); - } + playNext(); return; } -- cgit v1.2.3