diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-12-06 21:42:57 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-12-06 21:42:57 -0800 |
commit | 120427988bb76e16b35e48c8c9425d53c651f569 (patch) | |
tree | b8607e6bddbd7d0f693f4022e541a4f2d37847ee /subsonic-android/src | |
parent | 896a36011f4976f8caab058d02b66768306ba2e7 (diff) | |
download | dsub-120427988bb76e16b35e48c8c9425d53c651f569.tar.gz dsub-120427988bb76e16b35e48c8c9425d53c651f569.tar.bz2 dsub-120427988bb76e16b35e48c8c9425d53c651f569.zip |
Reworked onCompletionListener again
Diffstat (limited to 'subsonic-android/src')
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 90aec2b7..9a4ad899 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -820,12 +820,6 @@ public class DownloadServiceImpl extends Service implements DownloadService { setPlayerState(COMPLETED); - // If COMPLETED and file is completely cached - if (downloadFile.isWorkDone()) { - onSongCompleted(); - return; - } - // If file is not completely downloaded, restart the playback from the current position. int pos = mediaPlayer.getCurrentPosition(); if(pos == 0) { @@ -833,21 +827,25 @@ public class DownloadServiceImpl extends Service implements DownloadService { pos = cachedPosition; } synchronized (DownloadServiceImpl.this) { - // Work-around for apparent bug on certain phones: If close (less than ten seconds) to the end - // of the song, skip to the next rather than restarting it. - Integer duration = downloadFile.getSong().getDuration() == null ? null : downloadFile.getSong().getDuration() * 1000; - if (duration != null) { - if (Math.abs(duration - pos) < 10000) { - Log.i(TAG, "Skipping restart from " + pos + " of " + duration); - onSongCompleted(); - return; - } - } - - Log.i(TAG, "Requesting restart from " + pos + " of " + duration); - reset(); - bufferTask = new BufferTask(downloadFile, pos); - bufferTask.start(); + int duration = downloadFile.getSong().getDuration() == null ? 0 : downloadFile.getSong().getDuration() * 1000; + 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); + } + } else { + Log.i(TAG, "Requesting restart from " + pos + " of " + duration); + reset(); + bufferTask = new BufferTask(downloadFile, pos); + bufferTask.start(); + } } } }); |