diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-10-04 21:23:40 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-10-04 21:23:40 -0700 |
commit | c2dcb58813ac18f4717cf01ceeb4fe6a2e0bb7be (patch) | |
tree | d2069e66a22409fa3958c7b32bad5ce96fa11464 | |
parent | 3ec1f616594cbe77b8f1e196eab3fc2bfc1b47eb (diff) | |
download | dsub-c2dcb58813ac18f4717cf01ceeb4fe6a2e0bb7be.tar.gz dsub-c2dcb58813ac18f4717cf01ceeb4fe6a2e0bb7be.tar.bz2 dsub-c2dcb58813ac18f4717cf01ceeb4fe6a2e0bb7be.zip |
Rename file immediately on startup since StreamProxy is never released
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadFile.java | 7 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java | 15 |
2 files changed, 21 insertions, 1 deletions
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<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(); private int currentPlayingIndex; private int currentPlayingPosition; + private boolean renameCurrent = false; } } |