From c2dcb58813ac18f4717cf01ceeb4fe6a2e0bb7be Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 4 Oct 2013 21:23:40 -0700 Subject: Rename file immediately on startup since StreamProxy is never released --- src/github/daneren2005/dsub/service/DownloadFile.java | 7 +++++++ .../dsub/service/DownloadServiceLifecycleSupport.java | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src/github/daneren2005') diff --git a/src/github/daneren2005/dsub/service/DownloadFile.java b/src/github/daneren2005/dsub/service/DownloadFile.java index b7dea72e..40e11e9e 100644 --- a/src/github/daneren2005/dsub/service/DownloadFile.java +++ b/src/github/daneren2005/dsub/service/DownloadFile.java @@ -222,6 +222,13 @@ public class DownloadFile { this.isPlaying = isPlaying; } + public void renamePartial() { + try { + Util.renameFile(partialFile, completeFile); + } catch(IOException ex) { + Log.w(TAG, "Failed to rename file " + partialFile + " to " + completeFile); + } + } public boolean getPlaying() { return isPlaying; } diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index dbdd830d..299371c8 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -52,7 +52,7 @@ import github.daneren2005.dsub.util.Util; public class DownloadServiceLifecycleSupport { private static final String TAG = DownloadServiceLifecycleSupport.class.getSimpleName(); - private static final String FILENAME_DOWNLOADS_SER = "downloadstate.ser"; + private static final String FILENAME_DOWNLOADS_SER = "downloadstate2.ser"; private final DownloadServiceImpl downloadService; private Looper eventLooper; @@ -252,6 +252,11 @@ public class DownloadServiceLifecycleSupport { state.currentPlayingIndex = downloadService.getCurrentPlayingIndex(); state.currentPlayingPosition = downloadService.getPlayerPosition(); + DownloadFile currentPlaying = downloadService.getCurrentPlaying(); + if(currentPlaying != null) { + state.renameCurrent = currentPlaying.isWorkDone() && !currentPlaying.isCompleteFileAvailable(); + } + Log.i(TAG, "Serialized currentPlayingIndex: " + state.currentPlayingIndex + ", currentPlayingPosition: " + state.currentPlayingPosition); FileUtil.serialize(downloadService, state, FILENAME_DOWNLOADS_SER); } @@ -262,6 +267,13 @@ public class DownloadServiceLifecycleSupport { return; } Log.i(TAG, "Deserialized currentPlayingIndex: " + state.currentPlayingIndex + ", currentPlayingPosition: " + state.currentPlayingPosition); + + // Rename first thing before anything else starts + if(state.renameCurrent && state.currentPlayingIndex != -1 && state.currentPlayingIndex < state.songs.size()) { + DownloadFile currentPlaying = new DownloadFile(downloadService, state.songs.get(state.currentPlayingIndex), false); + currentPlaying.renamePartial(); + } + downloadService.restore(state.songs, state.currentPlayingIndex, state.currentPlayingPosition); } @@ -360,5 +372,6 @@ public class DownloadServiceLifecycleSupport { private List songs = new ArrayList(); private int currentPlayingIndex; private int currentPlayingPosition; + private boolean renameCurrent = false; } } -- cgit v1.2.3