aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-05-18 17:59:21 -0700
committerScott Jackson <daneren2005@gmail.com>2015-05-18 17:59:21 -0700
commit7d729d22eb00cebd73d0d74ecce817c3c81f5019 (patch)
tree04382238b71c23367dbe3cc3d2035308527884f9 /app/src/main/java
parent5e90403e4f9dcc4c1dcd415bedadd9cc66a5b830 (diff)
downloaddsub-7d729d22eb00cebd73d0d74ecce817c3c81f5019.tar.gz
dsub-7d729d22eb00cebd73d0d74ecce817c3c81f5019.tar.bz2
dsub-7d729d22eb00cebd73d0d74ecce817c3c81f5019.zip
Cache audio session id between plays
Diffstat (limited to 'app/src/main/java')
-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";