make replay gain a config option

This commit is contained in:
Adrian Ulrich committed 2013-03-23 20:08:06 +01:00
1 parent 4b3661523f
commit 6c225a1717
4 files changed
+26 -5

No files matched your search

+2
View File
@@ -152,6 +152,8 @@ THE SOFTWARE.
<string name="headset_pause_summary">Pause when the headphones are unplugged.</string>
<string name="headset_play_title">Play When Plugged</string>
<string name="headset_play_summary">Play when the headphones are plugged in. (Only works when the service is running.)</string>
<string name="replaygain_title">Enable replay gain</string>
<string name="replaygain_summary">Read replay gain information from tags and decrease volume if needed</string>
<string name="notifications">Notifications</string>
<string name="notification_mode_title">Notification Mode</string>
+5
View File
@@ -48,4 +48,9 @@ THE SOFTWARE.
android:title="@string/headset_play_title"
android:summary="@string/headset_play_summary"
android:defaultValue="false" />
<CheckBoxPreference
android:key="enable_replaygain"
android:title="@string/replaygain_title"
android:summary="@string/replaygain_summary"
android:defaultValue="false" />
</PreferenceScreen>
@@ -367,7 +367,11 @@ public final class PlaybackService extends Service
* of user settings.
*/
private boolean mForceNotificationVisible;
/**
* Enables or disables Replay Gain
*/
private boolean mReplayGainEnabled;
@Override
public void onCreate()
{
@@ -399,6 +403,7 @@ public final class PlaybackService extends Service
mHeadsetPause = getSettings(this).getBoolean(PrefKeys.HEADSET_PAUSE, true);
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;
mReplayGainEnabled = settings.getBoolean(PrefKeys.ENABLE_REPLAYGAIN, false);
PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VanillaMusicLock");
@@ -562,7 +567,15 @@ public final class PlaybackService extends Service
public void prepareMediaPlayer(MediaPlayer mp, String path) throws IOException{
mp.setDataSource(path);
/*
if(mReplayGainEnabled == true) {
applyReplayGain(mp, path);
}
mp.prepare();
}
private void applyReplayGain(MediaPlayer mp, String path) {
Hashtable tags = (new Bastp()).getTags(path);
float adjust = 1.0f;
@@ -576,12 +589,10 @@ public final class PlaybackService extends Service
} catch(Exception e) {}
adjust = (float)Math.pow(10, (rg_float/20) );
Toast.makeText(this, path+"\n"+" PX "+rg_raw+" adj = "+adjust, Toast.LENGTH_LONG).show();
Toast.makeText(this, path+"\n"+" PX "+rg_raw+" adj = "+adjust, Toast.LENGTH_SHORT).show();
}
mp.setVolume(adjust, adjust);
*/
mp.prepare();
}
/**
@@ -697,6 +708,8 @@ public final class PlaybackService extends Service
setupSensor();
} else if (PrefKeys.SHAKE_THRESHOLD.equals(key)) {
mShakeThreshold = settings.getInt(PrefKeys.SHAKE_THRESHOLD, 80) / 10.0f;
} else if (PrefKeys.ENABLE_REPLAYGAIN.equals(key)) {
mReplayGainEnabled = settings.getBoolean(PrefKeys.ENABLE_REPLAYGAIN, false);
}
CompatFroyo.dataChanged(this);
@@ -57,4 +57,5 @@ 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 ENABLE_REPLAYGAIN = "enable_replaygain";
}