aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java19
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java15
3 files changed, 29 insertions, 9 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
index 1c44fca1..a4222ce5 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
@@ -119,7 +119,6 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
private int swipeDistance;
private int swipeVelocity;
private VisualizerView visualizerView;
- private boolean equalizerOn;
private boolean nowPlaying = true;
private ScheduledFuture<?> hideControlsFuture;
@@ -276,9 +275,14 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
equalizerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- equalizerOn = true;
- startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class));
- setControlsVisible(true);
+ DownloadService downloadService = getDownloadService();
+ if(downloadService != null && downloadService.getEqualizerController() != null
+ && downloadService.getEqualizerController().getEqualizer() != null) {
+ startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class));
+ setControlsVisible(true);
+ } else {
+ Util.toast(DownloadActivity.this, "Failed to start equalizer. Try restarting.");
+ }
}
});
@@ -355,10 +359,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
if (!equalizerAvailable) {
equalizerButton.setVisibility(View.GONE);
- } else {
- SharedPreferences prefs = Util.getPreferences(DownloadActivity.this);
- equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false);
- }
+ }
if (!visualizerAvailable) {
visualizerButton.setVisibility(View.GONE);
} else {
@@ -451,6 +452,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
}
private void updateButtons() {
+ SharedPreferences prefs = Util.getPreferences(DownloadActivity.this);
+ boolean equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false);
if(equalizerOn && getDownloadService() != null && getDownloadService().getEqualizerController() != null &&
getDownloadService().getEqualizerController().isEnabled()) {
equalizerButton.setTextColor(COLOR_BUTTON_ENABLED);
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java
index 2aa61945..b4bd0e33 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java
@@ -86,6 +86,10 @@ public class EqualizerActivity extends Activity {
protected void onPause() {
super.onPause();
equalizerController.saveSettings();
+
+ if(!equalizer.getEnabled()) {
+ equalizerController.release();
+ }
}
@Override
diff --git a/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java b/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java
index f16ff968..0dcee863 100644
--- a/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java
+++ b/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java
@@ -38,6 +38,8 @@ public class EqualizerController {
private final Context context;
private Equalizer equalizer;
+ private boolean released = false;
+ private int audioSessionId = 0;
// Class initialization fails when this throws an exception.
static {
@@ -58,7 +60,8 @@ public class EqualizerController {
public EqualizerController(Context context, MediaPlayer mediaPlayer) {
this.context = context;
try {
- equalizer = new Equalizer(0, mediaPlayer.getAudioSessionId());
+ audioSessionId = mediaPlayer.getAudioSessionId();
+ equalizer = new Equalizer(0, audioSessionId);
} catch (Throwable x) {
Log.w(TAG, "Failed to create equalizer.", x);
}
@@ -97,11 +100,21 @@ public class EqualizerController {
public void release() {
if (isAvailable()) {
+ released = true;
equalizer.release();
}
}
public Equalizer getEqualizer() {
+ if(released) {
+ released = false;
+ try {
+ equalizer = new Equalizer(0, audioSessionId);
+ } catch (Throwable x) {
+ equalizer = null;
+ Log.w(TAG, "Failed to create equalizer.", x);
+ }
+ }
return equalizer;
}