aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaneren2005 <daneren2005@gmail.com>2013-04-11 15:23:42 -0700
committerdaneren2005 <daneren2005@gmail.com>2013-04-11 15:23:42 -0700
commitc6995ab8f18d000e2b31c35c7f72766a9f7f6941 (patch)
treebe1614c51f587200a2a711e896ab5b981aca33c8
parentfcbb28badb7d03f978fddc59b474c08388986910 (diff)
downloaddsub-c6995ab8f18d000e2b31c35c7f72766a9f7f6941.tar.gz
dsub-c6995ab8f18d000e2b31c35c7f72766a9f7f6941.tar.bz2
dsub-c6995ab8f18d000e2b31c35c7f72766a9f7f6941.zip
Instantiate a new nextMediaPlayer every time instead of reset
Reset doesn't seem to work well on certain phones (Galaxy S3) when using setNextMediaPlayer
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java38
1 files changed, 16 insertions, 22 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index 3dcbf6bb..f5ae6037 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -93,7 +93,8 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private boolean isPartial = true;
private final List<DownloadFile> downloadList = new ArrayList<DownloadFile>();
private final List<DownloadFile> backgroundDownloadList = new ArrayList<DownloadFile>();
- private final Handler handler = new Handler();
+ private final Handler handler = new Handler();
+ private Handler mediaPlayerHandler;
private final DownloadServiceLifecycleSupport lifecycleSupport = new DownloadServiceLifecycleSupport(this);
private final ShufflePlayBuffer shufflePlayBuffer = new ShufflePlayBuffer(this);
@@ -153,19 +154,9 @@ public class DownloadServiceImpl extends Service implements DownloadService {
return false;
}
});
-
- nextMediaPlayer = new MediaPlayer();
- nextMediaPlayer.setWakeMode(DownloadServiceImpl.this, PowerManager.PARTIAL_WAKE_LOCK);
-
- nextMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
- @Override
- public boolean onError(MediaPlayer mediaPlayer, int what, int more) {
- handleErrorNext(new Exception("MediaPlayer error: " + what + " (" + more + ")"));
- return false;
- }
- });
mediaPlayerLooper = Looper.myLooper();
+ mediaPlayerHandler = new Handler(mediaPlayerLooper);
Looper.loop();
}
}).start();
@@ -1055,14 +1046,13 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private synchronized void setupNext(final DownloadFile downloadFile) {
try {
final File file = downloadFile.isCompleteFileAvailable() ? downloadFile.getCompleteFile() : downloadFile.getPartialFile();
- nextMediaPlayer.setOnCompletionListener(null);
- try {
- nextMediaPlayer.setNextMediaPlayer(null);
- } catch(Exception e) {
- // Don't care, should only reach here if this is happening from uninitialized media player
- }
- nextMediaPlayer.reset();
- setNextPlayerState(IDLE);
+ if(nextMediaPlayer != null) {
+ nextMediaPlayer.setOnCompletionListener(null);
+ nextMediaPlayer.release();
+ nextMediaPlayer = null;
+ }
+ nextMediaPlayer = new MediaPlayer();
+ nextMediaPlayer.setWakeMode(DownloadServiceImpl.this, PowerManager.PARTIAL_WAKE_LOCK);
nextMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
nextMediaPlayer.setDataSource(file.getPath());
setNextPlayerState(PREPARING);
@@ -1453,8 +1443,12 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
}
- // Do something
- setupNext(downloadFile);
+ // Start the setup of the next media player
+ mediaPlayerHandler.post(new Runnable() {
+ public void run() {
+ setupNext(downloadFile);
+ }
+ });
}
private boolean bufferComplete() {