From 9f11830d6d5e1eb830952e825b6d6a223906e826 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 20 Dec 2013 18:42:24 -0800 Subject: Battery life improvements --- .../dsub/service/DownloadServiceImpl.java | 37 +++++++++++----------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 51c32091..aaf8c533 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -977,7 +977,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { if(mediaPlayer != null && playerState == STARTED) { cachedPosition = mediaPlayer.getCurrentPosition(); } - Thread.sleep(200L); + Thread.sleep(1000L); } catch(Exception e) { Log.w(TAG, "Crashed getting current position", e); @@ -1272,25 +1272,26 @@ public class DownloadServiceImpl extends Service implements DownloadService { Log.i(TAG, "Ending position " + pos + " of " + duration); if (!isPartial || (downloadFile.isWorkDone() && (Math.abs(duration - pos) < 10000))) { playNext(); - return; + } else { + // If file is not completely downloaded, restart the playback from the current position. + synchronized (DownloadServiceImpl.this) { + if(downloadFile.isWorkDone()) { + // Complete was called early even though file is fully buffered + 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(); + } + } } - // If file is not completely downloaded, restart the playback from the current position. - synchronized (DownloadServiceImpl.this) { - if(downloadFile.isWorkDone()) { - // Complete was called early even though file is fully buffered - 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(); - } - } + wakeLock.release(); } }); } -- cgit v1.2.3