aboutsummaryrefslogtreecommitdiff
path: root/src/github/daneren2005
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-03-02 07:35:11 -0800
committerScott Jackson <daneren2005@gmail.com>2014-03-02 07:35:11 -0800
commit4699dfddcbe616af65de672fcbbfc407cc65ceff (patch)
tree5a04910b4e3e1f7b6953512d6707af53acb0c744 /src/github/daneren2005
parenteba94bb2c6122414af0ea478f7b2b65ad1b2b39c (diff)
downloaddsub-4699dfddcbe616af65de672fcbbfc407cc65ceff.tar.gz
dsub-4699dfddcbe616af65de672fcbbfc407cc65ceff.tar.bz2
dsub-4699dfddcbe616af65de672fcbbfc407cc65ceff.zip
#287 Make EQ more reliable by keeping one session id
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r--src/github/daneren2005/dsub/audiofx/AudioEffectsController.java4
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java16
2 files changed, 14 insertions, 6 deletions
diff --git a/src/github/daneren2005/dsub/audiofx/AudioEffectsController.java b/src/github/daneren2005/dsub/audiofx/AudioEffectsController.java
index 16e30c6d..f53a4dff 100644
--- a/src/github/daneren2005/dsub/audiofx/AudioEffectsController.java
+++ b/src/github/daneren2005/dsub/audiofx/AudioEffectsController.java
@@ -36,9 +36,9 @@ public class AudioEffectsController {
private EqualizerController equalizerController;
private VisualizerController visualizerController;
- public AudioEffectsController(Context context, MediaPlayer mediaPlayer) {
+ public AudioEffectsController(Context context, int audioSessionId) {
this.context = context;
- audioSessionId = mediaPlayer.getAudioSessionId();
+ this.audioSessionId = audioSessionId;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
available = true;
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index fcf49ce6..7b4ddf31 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -97,6 +97,7 @@ public class DownloadService extends Service {
private Looper mediaPlayerLooper;
private MediaPlayer mediaPlayer;
private MediaPlayer nextMediaPlayer;
+ private int audioSessionId;
private boolean nextSetup = false;
private boolean isPartial = true;
private final List<DownloadFile> downloadList = new ArrayList<DownloadFile>();
@@ -154,6 +155,7 @@ public class DownloadService extends Service {
mediaPlayer = new MediaPlayer();
mediaPlayer.setWakeMode(DownloadService.this, PowerManager.PARTIAL_WAKE_LOCK);
+ mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
@@ -162,17 +164,19 @@ public class DownloadService extends Service {
return false;
}
});
+ audioSessionId = mediaPlayer.getAudioSessionId();
+ Log.d(TAG, "id: " + audioSessionId);
try {
Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
- i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.getAudioSessionId());
+ i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId);
i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
sendBroadcast(i);
} catch(Throwable e) {
// Froyo or lower
}
- effectsController = new AudioEffectsController(DownloadService.this, mediaPlayer);
+ effectsController = new AudioEffectsController(DownloadService.this, audioSessionId);
if(prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false)) {
getEqualizerController();
}
@@ -1222,7 +1226,11 @@ public class DownloadService extends Service {
mediaPlayer.setOnCompletionListener(null);
mediaPlayer.reset();
setPlayerState(IDLE);
- mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
+ try {
+ mediaPlayer.setAudioSessionId(audioSessionId);
+ } catch(Exception e) {
+ mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
+ }
String dataSource = file.getPath();
if(isPartial) {
if (proxy == null) {
@@ -1305,7 +1313,7 @@ public class DownloadService extends Service {
nextMediaPlayer = new MediaPlayer();
nextMediaPlayer.setWakeMode(DownloadService.this, PowerManager.PARTIAL_WAKE_LOCK);
try {
- nextMediaPlayer.setAudioSessionId(mediaPlayer.getAudioSessionId());
+ nextMediaPlayer.setAudioSessionId(audioSessionId);
} catch(Throwable e) {
nextMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}