aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--subsonic-android/res/layout-land/download.xml2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java40
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java105
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java15
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/audiofx/VisualizerController.java16
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java43
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Constants.java2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/view/VisualizerView.java15
9 files changed, 198 insertions, 44 deletions
diff --git a/subsonic-android/res/layout-land/download.xml b/subsonic-android/res/layout-land/download.xml
index 431fef96..4992d169 100644
--- a/subsonic-android/res/layout-land/download.xml
+++ b/subsonic-android/res/layout-land/download.xml
@@ -53,7 +53,6 @@
android:text="EQ"
android:textStyle="bold"
android:textSize="22sp"
- android:visibility="gone"
android:background="@android:color/transparent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -76,7 +75,6 @@
android:text="VIS"
android:textStyle="bold"
android:textSize="22sp"
- android:visibility="gone"
android:background="@android:color/transparent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
index dd5b3f0a..a4222ce5 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
@@ -275,8 +275,14 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
equalizerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- 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.");
+ }
}
});
@@ -285,9 +291,14 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
public void onClick(View view) {
boolean active = !visualizerView.isActive();
visualizerView.setActive(active);
- getDownloadService().setShowVisualization(visualizerView.isActive());
+ boolean isActive = visualizerView.isActive();
+ getDownloadService().setShowVisualization(isActive);
updateButtons();
- Util.toast(DownloadActivity.this, active ? R.string.download_visualizer_on : R.string.download_visualizer_off);
+ if(active == isActive) {
+ Util.toast(DownloadActivity.this, active ? R.string.download_visualizer_on : R.string.download_visualizer_off);
+ } else {
+ Util.toast(DownloadActivity.this, "Failed to start visualizer. Try restarting.");
+ }
setControlsVisible(true);
}
});
@@ -343,8 +354,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
downloadService.setShufflePlayEnabled(true);
}
- boolean visualizerAvailable = downloadService != null && downloadService.getVisualizerController() != null;
- boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerController() != null;
+ boolean visualizerAvailable = downloadService != null && downloadService.getVisualizerAvailable();
+ boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerAvailable();
if (!equalizerAvailable) {
equalizerButton.setVisibility(View.GONE);
@@ -400,8 +411,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
- if (visualizerView != null) {
- visualizerView.setActive(downloadService != null && downloadService.getShowVisualization());
+ if (visualizerView != null && downloadService != null && downloadService.getShowVisualization()) {
+ visualizerView.setActive(true);
}
updateButtons();
@@ -441,10 +452,15 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
}
private void updateButtons() {
- boolean eqEnabled = getDownloadService() != null && getDownloadService().getEqualizerController() != null &&
- getDownloadService().getEqualizerController().isEnabled();
- equalizerButton.setTextColor(eqEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
-
+ 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);
+ } else {
+ equalizerButton.setTextColor(COLOR_BUTTON_DISABLED);
+ }
+
if (visualizerView != null) {
visualizerButton.setTextColor(visualizerView.isActive() ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java
index 9906673a..e5de3858 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java
@@ -22,8 +22,10 @@ import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
+import android.content.SharedPreferences;
import android.media.audiofx.Equalizer;
import android.os.Bundle;
+import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
@@ -36,6 +38,8 @@ import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.audiofx.EqualizerController;
import github.daneren2005.dsub.service.DownloadServiceImpl;
+import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.Util;
/**
* Equalizer controls.
@@ -44,12 +48,14 @@ import github.daneren2005.dsub.service.DownloadServiceImpl;
* @version $Id$
*/
public class EqualizerActivity extends Activity {
+ private static final String TAG = EqualizerActivity.class.getSimpleName();
private static final int MENU_GROUP_PRESET = 100;
private final Map<Short, SeekBar> bars = new HashMap<Short, SeekBar>();
private EqualizerController equalizerController;
private Equalizer equalizer;
+ private short masterLevel = 0;
@Override
public void onCreate(Bundle bundle) {
@@ -83,6 +89,17 @@ public class EqualizerActivity extends Activity {
protected void onPause() {
super.onPause();
equalizerController.saveSettings();
+
+ if(!equalizer.getEnabled()) {
+ equalizerController.release();
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ equalizerController = DownloadServiceImpl.getInstance().getEqualizerController();
+ equalizer = equalizerController.getEqualizer();
}
@Override
@@ -109,24 +126,46 @@ public class EqualizerActivity extends Activity {
public boolean onContextItemSelected(MenuItem menuItem) {
short preset = (short) menuItem.getItemId();
equalizer.usePreset(preset);
- updateBars();
+ updateBars(false);
return true;
}
private void setEqualizerEnabled(boolean enabled) {
+ SharedPreferences prefs = Util.getPreferences(EqualizerActivity.this);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putBoolean(Constants.PREFERENCES_EQUALIZER_ON, enabled);
+ editor.commit();
equalizer.setEnabled(enabled);
- updateBars();
+ updateBars(true);
}
- private void updateBars() {
-
+ private void updateBars(boolean changedEnabled) {
+ boolean isEnabled = equalizer.getEnabled();
+ short minEQLevel = equalizer.getBandLevelRange()[0];
for (Map.Entry<Short, SeekBar> entry : bars.entrySet()) {
short band = entry.getKey();
SeekBar bar = entry.getValue();
- bar.setEnabled(equalizer.getEnabled());
- short minEQLevel = equalizer.getBandLevelRange()[0];
- bar.setProgress(equalizer.getBandLevel(band) - minEQLevel);
+ bar.setEnabled(isEnabled);
+ if(band >= (short)0) {
+ if(changedEnabled) {
+ equalizer.setBandLevel(band, (short)(equalizer.getBandLevel(band) - masterLevel));
+ bar.setProgress(equalizer.getBandLevel(band) - minEQLevel);
+ } else {
+ bar.setProgress(equalizer.getBandLevel(band) - minEQLevel);
+ equalizer.setBandLevel(band, (short)(equalizer.getBandLevel(band) + masterLevel));
+ }
+ } else if(!isEnabled) {
+ bar.setProgress(-minEQLevel);
+ }
}
+
+ if(!isEnabled) {
+ masterLevel = 0;
+ SharedPreferences prefs = Util.getPreferences(EqualizerActivity.this);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, masterLevel);
+ editor.commit();
+ }
}
private void initEqualizer() {
@@ -134,6 +173,11 @@ public class EqualizerActivity extends Activity {
final short minEQLevel = equalizer.getBandLevelRange()[0];
final short maxEQLevel = equalizer.getBandLevelRange()[1];
+
+ // Setup Pregain
+ SharedPreferences prefs = Util.getPreferences(this);
+ masterLevel = (short)prefs.getInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, 0);
+ initPregain(layout, minEQLevel, maxEQLevel);
for (short i = 0; i < equalizer.getNumberOfBands(); i++) {
final short band = i;
@@ -148,6 +192,9 @@ public class EqualizerActivity extends Activity {
bars.put(band, bar);
bar.setMax(maxEQLevel - minEQLevel);
short level = equalizer.getBandLevel(band);
+ if(equalizer.getEnabled()) {
+ level = (short) (level - masterLevel);
+ }
bar.setProgress(level - minEQLevel);
bar.setEnabled(equalizer.getEnabled());
updateLevelText(levelTextView, level);
@@ -157,7 +204,7 @@ public class EqualizerActivity extends Activity {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
short level = (short) (progress + minEQLevel);
if (fromUser) {
- equalizer.setBandLevel(band, level);
+ equalizer.setBandLevel(band, (short)(level + masterLevel));
}
updateLevelText(levelTextView, level);
}
@@ -173,6 +220,48 @@ public class EqualizerActivity extends Activity {
layout.addView(bandBar);
}
}
+
+ private void initPregain(LinearLayout layout, final short minEQLevel, final short maxEQLevel) {
+ View bandBar = LayoutInflater.from(this).inflate(R.layout.equalizer_bar, null);
+ TextView freqTextView = (TextView) bandBar.findViewById(R.id.equalizer_frequency);
+ final TextView levelTextView = (TextView) bandBar.findViewById(R.id.equalizer_level);
+ SeekBar bar = (SeekBar) bandBar.findViewById(R.id.equalizer_bar);
+
+ freqTextView.setText("Master");
+
+ bars.put((short)-1, bar);
+ bar.setMax(maxEQLevel - minEQLevel);
+ bar.setProgress(masterLevel - minEQLevel);
+ bar.setEnabled(equalizer.getEnabled());
+ updateLevelText(levelTextView, masterLevel);
+
+ bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ masterLevel = (short) (progress + minEQLevel);
+ if (fromUser) {
+ SharedPreferences prefs = Util.getPreferences(EqualizerActivity.this);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, masterLevel);
+ editor.commit();
+ for (short i = 0; i < equalizer.getNumberOfBands(); i++) {
+ short level = (short) ((bars.get(i).getProgress() + minEQLevel) + masterLevel);
+ equalizer.setBandLevel(i, level);
+ }
+ }
+ updateLevelText(levelTextView, masterLevel);
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+ });
+ layout.addView(bandBar);
+ }
private void updateLevelText(TextView levelTextView, short level) {
levelTextView.setText((level > 0 ? "+" : "") + level / 100 + " dB");
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;
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/audiofx/VisualizerController.java b/subsonic-android/src/github/daneren2005/dsub/audiofx/VisualizerController.java
index 184aeb51..b32245f4 100644
--- a/subsonic-android/src/github/daneren2005/dsub/audiofx/VisualizerController.java
+++ b/subsonic-android/src/github/daneren2005/dsub/audiofx/VisualizerController.java
@@ -36,6 +36,8 @@ public class VisualizerController {
private final Context context;
private Visualizer visualizer;
+ private boolean released = false;
+ private int audioSessionId = 0;
// Class initialization fails when this throws an exception.
static {
@@ -56,7 +58,8 @@ public class VisualizerController {
public VisualizerController(Context context, MediaPlayer mediaPlayer) {
this.context = context;
try {
- visualizer = new Visualizer(mediaPlayer.getAudioSessionId());
+ audioSessionId = mediaPlayer.getAudioSessionId();
+ visualizer = new Visualizer(audioSessionId);
} catch (Throwable x) {
Log.w(TAG, "Failed to create visualizer.", x);
}
@@ -80,10 +83,21 @@ public class VisualizerController {
public void release() {
if (isAvailable()) {
visualizer.release();
+ released = true;
}
}
public Visualizer getVisualizer() {
+ if(released) {
+ released = false;
+ try {
+ visualizer = new Visualizer(audioSessionId);
+ } catch (Throwable x) {
+ visualizer = null;
+ Log.w(TAG, "Failed to create visualizer.", x);
+ }
+ }
+
return visualizer;
}
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java
index 663a6e6c..0536c198 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java
@@ -106,6 +106,10 @@ public interface DownloadService {
void setSuggestedPlaylistName(String name);
String getSuggestedPlaylistName();
+
+ boolean getEqualizerAvailable();
+
+ boolean getVisualizerAvailable();
EqualizerController getEqualizerController();
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index 72198850..9e6662cf 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -158,21 +158,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
mRemoteControl.register(this, mediaButtonReceiverComponent);
}
- if (equalizerAvailable) {
- equalizerController = new EqualizerController(this, mediaPlayer);
- if (!equalizerController.isAvailable()) {
- equalizerController = null;
- } else {
- equalizerController.loadSettings();
- }
- }
- if (visualizerAvailable) {
- visualizerController = new VisualizerController(this, mediaPlayer);
- if (!visualizerController.isAvailable()) {
- visualizerController = null;
- }
- }
-
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
wakeLock.setReferenceCounted(false);
@@ -189,6 +174,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
instance = this;
lifecycleSupport.onCreate();
+
+ if(prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false)) {
+ getEqualizerController();
+ }
}
@Override
@@ -781,14 +770,38 @@ public class DownloadServiceImpl extends Service implements DownloadService {
public String getSuggestedPlaylistName() {
return suggestedPlaylistName;
}
+
+ @Override
+ public boolean getEqualizerAvailable() {
+ return equalizerAvailable;
+ }
+
+ @Override
+ public boolean getVisualizerAvailable() {
+ return visualizerAvailable;
+ }
@Override
public EqualizerController getEqualizerController() {
+ if (equalizerAvailable && equalizerController == null) {
+ equalizerController = new EqualizerController(this, mediaPlayer);
+ if (!equalizerController.isAvailable()) {
+ equalizerController = null;
+ } else {
+ equalizerController.loadSettings();
+ }
+ }
return equalizerController;
}
@Override
public VisualizerController getVisualizerController() {
+ if (visualizerAvailable && visualizerController == null) {
+ visualizerController = new VisualizerController(this, mediaPlayer);
+ if (!visualizerController.isAvailable()) {
+ visualizerController = null;
+ }
+ }
return visualizerController;
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
index c116c484..3ee7d7e8 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
@@ -88,6 +88,8 @@ public final class Constants {
public static final String PREFERENCES_KEY_SHUFFLE_GENRE = "genre";
public static final String PREFERENCES_KEY_KEEP_SCREEN_ON = "keepScreenOn";
public static final String PREFERENCES_KEY_BUFFER_LENGTH = "bufferLength";
+ public static final String PREFERENCES_EQUALIZER_ON = "equalizerOn";
+ public static final String PREFERENCES_EQUALIZER_SETTINGS = "equalizerSettings";
// Name of the preferences file.
public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences";
diff --git a/subsonic-android/src/github/daneren2005/dsub/view/VisualizerView.java b/subsonic-android/src/github/daneren2005/dsub/view/VisualizerView.java
index 9bff3a2d..53ebc2ec 100644
--- a/subsonic-android/src/github/daneren2005/dsub/view/VisualizerView.java
+++ b/subsonic-android/src/github/daneren2005/dsub/view/VisualizerView.java
@@ -45,14 +45,14 @@ public class VisualizerView extends View {
private byte[] data;
private float[] points;
- private boolean active;
+ private boolean active = false;
public VisualizerView(Context context) {
super(context);
paint.setStrokeWidth(2f);
paint.setAntiAlias(true);
- paint.setColor(Color.rgb(129, 201, 54));
+ paint.setColor(Color.rgb(51, 181, 229));
}
public boolean isActive() {
@@ -61,8 +61,10 @@ public class VisualizerView extends View {
public void setActive(boolean active) {
this.active = active;
- Visualizer visualizer = getVizualiser();
+ VisualizerController visualizerController = getVizualiser();
+ Visualizer visualizer = visualizerController == null ? null : visualizerController.getVisualizer();
if (visualizer == null) {
+ this.active = false;
return;
}
@@ -83,13 +85,16 @@ public class VisualizerView extends View {
}
visualizer.setEnabled(active);
+ if(!active) {
+ visualizerController.release();
+ }
invalidate();
}
- private Visualizer getVizualiser() {
+ private VisualizerController getVizualiser() {
DownloadService downloadService = DownloadServiceImpl.getInstance();
VisualizerController visualizerController = downloadService == null ? null : downloadService.getVisualizerController();
- return visualizerController == null ? null : visualizerController.getVisualizer();
+ return visualizerController;
}
private void updateVisualizer(byte[] waveform) {