diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-07-07 08:29:52 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-07-07 08:29:52 -0700 |
commit | 6ebae86dfbb7fa79d81e6b2485f395eeab7267ef (patch) | |
tree | bc26b39df3c6a666bcac960042f2ac8cb06ad202 /subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx | |
parent | 8a7bb33f73d4fab1e380adf972efc2f3a7ee8b3e (diff) | |
download | dsub-6ebae86dfbb7fa79d81e6b2485f395eeab7267ef.tar.gz dsub-6ebae86dfbb7fa79d81e6b2485f395eeab7267ef.tar.bz2 dsub-6ebae86dfbb7fa79d81e6b2485f395eeab7267ef.zip |
Changed project package to github.daneren2005.subphonic
Diffstat (limited to 'subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx')
2 files changed, 0 insertions, 228 deletions
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/EqualizerController.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/EqualizerController.java deleted file mode 100644 index 77a270ed..00000000 --- a/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/EqualizerController.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - This file is part of Subsonic. - - Subsonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Subsonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Subsonic. If not, see <http://www.gnu.org/licenses/>. - - Copyright 2011 (C) Sindre Mehus - */ -package net.sourceforge.subsonic.androidapp.audiofx; - -import java.io.Serializable; - -import android.content.Context; -import android.media.MediaPlayer; -import android.media.audiofx.Equalizer; -import android.util.Log; -import net.sourceforge.subsonic.androidapp.util.FileUtil; - -/** - * Backward-compatible wrapper for {@link Equalizer}, which is API Level 9. - * - * @author Sindre Mehus - * @version $Id$ - */ -public class EqualizerController { - - private static final String TAG = EqualizerController.class.getSimpleName(); - - private final Context context; - private Equalizer equalizer; - - // Class initialization fails when this throws an exception. - static { - try { - Class.forName("android.media.audiofx.Equalizer"); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - /** - * Throws an exception if the {@link Equalizer} class is not available. - */ - public static void checkAvailable() throws Throwable { - // Calling here forces class initialization. - } - - public EqualizerController(Context context, MediaPlayer mediaPlayer) { - this.context = context; - try { - equalizer = new Equalizer(0, mediaPlayer.getAudioSessionId()); - } catch (Throwable x) { - Log.w(TAG, "Failed to create equalizer.", x); - } - } - - public void saveSettings() { - try { - if (isAvailable()) { - FileUtil.serialize(context, new EqualizerSettings(equalizer), "equalizer.dat"); - } - } catch (Throwable x) { - Log.w(TAG, "Failed to save equalizer settings.", x); - } - } - - public void loadSettings() { - try { - if (isAvailable()) { - EqualizerSettings settings = FileUtil.deserialize(context, "equalizer.dat"); - if (settings != null) { - settings.apply(equalizer); - } - } - } catch (Throwable x) { - Log.w(TAG, "Failed to load equalizer settings.", x); - } - } - - public boolean isAvailable() { - return equalizer != null; - } - - public boolean isEnabled() { - return isAvailable() && equalizer.getEnabled(); - } - - public void release() { - if (isAvailable()) { - equalizer.release(); - } - } - - public Equalizer getEqualizer() { - return equalizer; - } - - private static class EqualizerSettings implements Serializable { - - private final short[] bandLevels; - private short preset; - private final boolean enabled; - - public EqualizerSettings(Equalizer equalizer) { - enabled = equalizer.getEnabled(); - bandLevels = new short[equalizer.getNumberOfBands()]; - for (short i = 0; i < equalizer.getNumberOfBands(); i++) { - bandLevels[i] = equalizer.getBandLevel(i); - } - try { - preset = equalizer.getCurrentPreset(); - } catch (Exception x) { - preset = -1; - } - } - - public void apply(Equalizer equalizer) { - for (short i = 0; i < bandLevels.length; i++) { - equalizer.setBandLevel(i, bandLevels[i]); - } - if (preset >= 0 && preset < equalizer.getNumberOfPresets()) { - equalizer.usePreset(preset); - } - equalizer.setEnabled(enabled); - } - } -} - diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/VisualizerController.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/VisualizerController.java deleted file mode 100644 index 9a211b58..00000000 --- a/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/VisualizerController.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - This file is part of Subsonic. - - Subsonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Subsonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Subsonic. If not, see <http://www.gnu.org/licenses/>. - - Copyright 2011 (C) Sindre Mehus - */ -package net.sourceforge.subsonic.androidapp.audiofx; - -import android.content.Context; -import android.media.MediaPlayer; -import android.media.audiofx.Visualizer; -import android.util.Log; - -/** - * Backward-compatible wrapper for {@link Visualizer}, which is API Level 9. - * - * @author Sindre Mehus - * @version $Id$ - */ -public class VisualizerController { - - private static final String TAG = VisualizerController.class.getSimpleName(); - private static final int PREFERRED_CAPTURE_SIZE = 128; // Must be a power of two. - - private final Context context; - private Visualizer visualizer; - - // Class initialization fails when this throws an exception. - static { - try { - Class.forName("android.media.audiofx.Visualizer"); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - /** - * Throws an exception if the {@link Visualizer} class is not available. - */ - public static void checkAvailable() throws Throwable { - // Calling here forces class initialization. - } - - public VisualizerController(Context context, MediaPlayer mediaPlayer) { - this.context = context; - try { - visualizer = new Visualizer(mediaPlayer.getAudioSessionId()); - } catch (Throwable x) { - Log.w(TAG, "Failed to create visualizer.", x); - } - - if (visualizer != null) { - int[] captureSizeRange = Visualizer.getCaptureSizeRange(); - int captureSize = Math.max(PREFERRED_CAPTURE_SIZE, captureSizeRange[0]); - captureSize = Math.min(captureSize, captureSizeRange[1]); - visualizer.setCaptureSize(captureSize); - } - } - - public boolean isAvailable() { - return visualizer != null; - } - - public boolean isEnabled() { - return isAvailable() && visualizer.getEnabled(); - } - - public void release() { - if (isAvailable()) { - visualizer.release(); - } - } - - public Visualizer getVisualizer() { - return visualizer; - } -} - |