aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java29
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Constants.java1
2 files changed, 24 insertions, 6 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
index c1f8870e..eb61a579 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -42,6 +42,7 @@ import github.daneren2005.dsub.domain.RepeatMode;
import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.receiver.MediaButtonIntentReceiver;
import github.daneren2005.dsub.util.ArtistRadioBuffer;
+import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Notifications;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.Constants;
@@ -174,7 +175,28 @@ public class DownloadService extends Service {
mediaPlayer = new MediaPlayer();
mediaPlayer.setWakeMode(DownloadService.this, PowerManager.PARTIAL_WAKE_LOCK);
- mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
+
+ audioSessionId = -1;
+ Integer id = prefs.getInt(Constants.CACHE_AUDIO_SESSION_ID, -1);
+ if(id != -1) {
+ try {
+ audioSessionId = id;
+ mediaPlayer.setAudioSessionId(audioSessionId);
+ } catch (Throwable e) {
+ audioSessionId = -1;
+ }
+ }
+
+ if(audioSessionId == -1) {
+ mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
+ try {
+ audioSessionId = mediaPlayer.getAudioSessionId();
+ prefs.edit().putInt(Constants.CACHE_AUDIO_SESSION_ID, audioSessionId).commit();
+ } catch (Throwable t) {
+ // Froyo or lower
+ }
+ }
+ Log.d(TAG, "Audio session id: " + audioSessionId);
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
@@ -183,11 +205,6 @@ public class DownloadService extends Service {
return false;
}
});
- try {
- audioSessionId = mediaPlayer.getAudioSessionId();
- } catch(Throwable e) {
- // Froyo or lower
- }
try {
Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
index 31c5bef2..05481bf0 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
@@ -168,6 +168,7 @@ public final class Constants {
public static final String OFFLINE_STAR_SETTING = "starSetting";
public static final String CACHE_KEY_IGNORE = "ignoreArticles";
+ public static final String CACHE_AUDIO_SESSION_ID = "audioSessionId";
public static final String MAIN_BACK_STACK = "backStackIds";
public static final String MAIN_BACK_STACK_SIZE = "backStackIdsSize";