Remove volume override feature
This seems to be pretty buggy for some reason (android bug?) and crashes with random errors - even on freshly initialized MediaPlayers
This commit is contained in:
1 parent
b14299e6da
commit
5eab4898ee
4 files changed
+3
-122
No files matched your search
@@ -23,12 +23,6 @@ THE SOFTWARE.
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:persistent="true">
|
||||
<ch.blinkenlights.android.vanilla.SeekBarPreference
|
||||
android:key="volume_int"
|
||||
android:negativeButtonText="@null"
|
||||
android:dialogLayout="@layout/shake_pref"
|
||||
android:defaultValue="100"
|
||||
android:title="@string/volume_title" />
|
||||
<CheckBoxPreference
|
||||
android:key="media_button"
|
||||
android:title="@string/media_button_title"
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Christopher Eby <kreed@kreed.org>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package ch.blinkenlights.android.vanilla;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.audiofx.Equalizer;
|
||||
|
||||
/**
|
||||
* Gingerbread equalizer compatibility.
|
||||
*/
|
||||
@TargetApi(9)
|
||||
public class CompatEq {
|
||||
private final Equalizer mEq;
|
||||
|
||||
/**
|
||||
* Create the equalizer and attach it to the given MediaPlayer's audio
|
||||
* session.
|
||||
*/
|
||||
public CompatEq(MediaPlayer player)
|
||||
{
|
||||
Equalizer eq = new Equalizer(0, player.getAudioSessionId());
|
||||
eq.setEnabled(true);
|
||||
mEq = eq;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call {@link Equalizer#getNumberOfBands()}
|
||||
*/
|
||||
public short getNumberOfBands()
|
||||
{
|
||||
return mEq.getNumberOfBands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call {@link Equalizer#setBandLevel(short, short)}.
|
||||
*/
|
||||
public void setBandLevel(short band, short level)
|
||||
{
|
||||
mEq.setBandLevel(band, level);
|
||||
}
|
||||
}
|
||||
@@ -305,10 +305,6 @@ public final class PlaybackService extends Service
|
||||
* The SensorManager service.
|
||||
*/
|
||||
private SensorManager mSensorManager;
|
||||
/**
|
||||
* The equalizer wrapper.
|
||||
*/
|
||||
private CompatEq mEqualizer;
|
||||
|
||||
SongTimeline mTimeline;
|
||||
private Song mCurrentSong;
|
||||
@@ -329,14 +325,6 @@ public final class PlaybackService extends Service
|
||||
public Receiver mReceiver;
|
||||
public InCallListener mCallListener;
|
||||
private String mErrorMessage;
|
||||
/**
|
||||
* The volume adjustment set in the volume preference.
|
||||
*/
|
||||
private float mUserVolume;
|
||||
/**
|
||||
* The linear scale volume set on the MediaPlayer.
|
||||
*/
|
||||
private float mBaseVolume;
|
||||
/**
|
||||
* If true, the volume is being reduced for the idle fade-out.
|
||||
*/
|
||||
@@ -388,14 +376,6 @@ public final class PlaybackService extends Service
|
||||
|
||||
mMediaPlayer = getNewMediaPlayer();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
||||
try {
|
||||
mEqualizer = new CompatEq(mMediaPlayer);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// equalizer not supported
|
||||
}
|
||||
}
|
||||
|
||||
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||
mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
|
||||
|
||||
@@ -407,7 +387,6 @@ public final class PlaybackService extends Service
|
||||
settings.registerOnSharedPreferenceChangeListener(this);
|
||||
mNotificationMode = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_MODE, "1"));
|
||||
mScrobble = settings.getBoolean(PrefKeys.SCROBBLE, false);
|
||||
mUserVolume = (float)Math.pow(settings.getInt(PrefKeys.VOLUME, 100) / 100.0, 3);
|
||||
mIdleTimeout = settings.getBoolean(PrefKeys.USE_IDLE_TIMEOUT, false) ? settings.getInt(PrefKeys.IDLE_TIMEOUT, 3600) : 0;
|
||||
Song.mDisableCoverArt = settings.getBoolean(PrefKeys.DISABLE_COVER_ART, false);
|
||||
mHeadsetOnly = settings.getBoolean(PrefKeys.HEADSET_ONLY, false);
|
||||
@@ -419,8 +398,6 @@ public final class PlaybackService extends Service
|
||||
mShakeAction = settings.getBoolean(PrefKeys.ENABLE_SHAKE, false) ? Action.getAction(settings, PrefKeys.SHAKE_ACTION, Action.NextSong) : Action.Nothing;
|
||||
mShakeThreshold = settings.getInt(PrefKeys.SHAKE_THRESHOLD, 80) / 10.0f;
|
||||
|
||||
updateVolume();
|
||||
|
||||
PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE);
|
||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VanillaMusicLock");
|
||||
|
||||
@@ -649,30 +626,6 @@ public final class PlaybackService extends Service
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volume gain on the MediaPlayer/Equalizer
|
||||
*/
|
||||
private void updateVolume()
|
||||
{
|
||||
float base = mUserVolume;
|
||||
|
||||
if (base > 1.0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
||||
// In Gingerbread and above, MediaPlayer no longer accepts volumes
|
||||
// > 1.0. So we use an equalizer instead.
|
||||
CompatEq eq = mEqualizer;
|
||||
if (eq != null) {
|
||||
short gain = (short)(2000 * Math.log10(base));
|
||||
for (short i = eq.getNumberOfBands(); --i != -1; ) {
|
||||
eq.setBandLevel(i, gain);
|
||||
}
|
||||
}
|
||||
base = 1.0f;
|
||||
}
|
||||
|
||||
mBaseVolume = base;
|
||||
if (mMediaPlayer != null)
|
||||
mMediaPlayer.setVolume(base, base);
|
||||
}
|
||||
|
||||
private void loadPreference(String key)
|
||||
{
|
||||
@@ -694,9 +647,6 @@ public final class PlaybackService extends Service
|
||||
updateNotification();
|
||||
} else if (PrefKeys.SCROBBLE.equals(key)) {
|
||||
mScrobble = settings.getBoolean(PrefKeys.SCROBBLE, false);
|
||||
} else if (PrefKeys.VOLUME.equals(key)) {
|
||||
mUserVolume = (float)Math.pow(settings.getInt(key, 100) / 100.0, 3);
|
||||
updateVolume();
|
||||
} else if (PrefKeys.MEDIA_BUTTON.equals(key) || PrefKeys.MEDIA_BUTTON_BEEP.equals(key)) {
|
||||
MediaButtonReceiver.reloadPreference(this);
|
||||
} else if (PrefKeys.USE_IDLE_TIMEOUT.equals(key) || PrefKeys.IDLE_TIMEOUT.equals(key)) {
|
||||
@@ -1318,12 +1268,12 @@ public final class PlaybackService extends Service
|
||||
if (progress == 0) {
|
||||
mIdleStart = SystemClock.elapsedRealtime();
|
||||
unsetFlag(FLAG_PLAYING);
|
||||
volume = mBaseVolume;
|
||||
volume = 1.0f;
|
||||
mFadeInProgress = false;
|
||||
} else {
|
||||
// Approximate an exponential curve with x^4
|
||||
// http://www.dr-lex.be/info-stuff/volumecontrols.html
|
||||
volume = Math.max((float)(Math.pow(progress / 100f, 4) * mBaseVolume), .01f);
|
||||
volume = Math.max((float)(Math.pow(progress / 100f, 4) * 1.0f), .01f);
|
||||
mHandler.sendMessageDelayed(mHandler.obtainMessage(FADE_OUT, progress, 0), 50);
|
||||
}
|
||||
if (mMediaPlayer != null)
|
||||
@@ -1468,7 +1418,7 @@ public final class PlaybackService extends Service
|
||||
mHandler.sendEmptyMessageDelayed(IDLE_TIMEOUT, mIdleTimeout * 1000);
|
||||
|
||||
if (mFadeInProgress) {
|
||||
mMediaPlayer.setVolume(mBaseVolume, mBaseVolume);
|
||||
mMediaPlayer.setVolume(1.0f, 1.0f);
|
||||
mFadeInProgress = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,5 +57,4 @@ public class PrefKeys {
|
||||
public static final String USE_IDLE_TIMEOUT = "use_idle_timeout";
|
||||
public static final String VISIBLE_CONTROLS = "visible_controls";
|
||||
public static final String VISIBLE_EXTRA_INFO = "visible_extra_info";
|
||||
public static final String VOLUME = "volume_int";
|
||||
}
|
||||
Reference in new issue
Block a user