Applied ducking state to prepared media play. Renamed *OnVolume to *OnDucking for consistency. Added is-playing check before initiating ducking. Replaced switch on String to if else for source compatability.

This commit is contained in:
Xiao Bao Clark 2015-08-29 08:54:34 +10:00
parent ea9302aa0a
commit f73bd0fdde
6 changed files with 31 additions and 27 deletions

View File

@ -150,8 +150,8 @@ THE SOFTWARE.
<string name="audio">Audio</string>
<string name="volume_title">Volume</string>
<string name="volume_on_notification_title">Volume During Notification</string>
<string name="volume_on_notification_summary">Playback volume: </string>
<string name="volume_during_ducking_title">Volume During Notification</string>
<string name="volume_during_ducking_summary">Playback volume: </string>
<string name="media_button_title">Headset/Bluetooth Controls</string>
<string name="media_button_summary">This is also required for ICS lockscreen controls.</string>
<string name="media_button_beep_title">Headset Control Beep</string>

View File

@ -32,10 +32,10 @@ THE SOFTWARE.
android:title="@string/replaygain"
android:summary="@string/replaygain_summary" />
<ch.blinkenlights.android.vanilla.SeekBarPreference
android:key="volume_on_notification"
android:key="volume_during_ducking"
android:negativeButtonText="@string/restore_default"
android:dialogLayout="@layout/shake_pref"
android:title="@string/volume_on_notification_title"
android:title="@string/volume_during_ducking_title"
android:defaultValue="50" />
<CheckBoxPreference
android:key="media_button"

View File

@ -394,7 +394,7 @@ public final class PlaybackService extends Service
/**
* Percentage to set the volume as while a notification is playing (aka ducking)
*/
private int mVolumeOnNotification;
private int mVolumeDuringDucking;
/**
* TRUE if the readahead feature is enabled
*/
@ -460,7 +460,7 @@ public final class PlaybackService extends Service
mReplayGainBump = settings.getInt(PrefKeys.REPLAYGAIN_BUMP, 75); /* seek bar is 150 -> 75 == middle == 0 */
mReplayGainUntaggedDeBump = settings.getInt(PrefKeys.REPLAYGAIN_UNTAGGED_DEBUMP, 150); /* seek bar is 150 -> == 0 */
mVolumeOnNotification = settings.getInt(PrefKeys.VOLUME_ON_NOTIFICATION, 50);
mVolumeDuringDucking = settings.getInt(PrefKeys.VOLUME_DURING_DUCKING, 50);
refreshDuckingValues();
mReadaheadEnabled = settings.getBoolean(PrefKeys.ENABLE_READAHEAD, false);
@ -636,7 +636,7 @@ public final class PlaybackService extends Service
}
private void refreshDuckingValues() {
float duckingFactor = ((float)mVolumeOnNotification)/100f;
float duckingFactor = ((float) mVolumeDuringDucking)/100f;
mMediaPlayer.setDuckingFactor(duckingFactor);
mPreparedMediaPlayer.setDuckingFactor(duckingFactor);
}
@ -862,8 +862,8 @@ public final class PlaybackService extends Service
} else if (PrefKeys.REPLAYGAIN_UNTAGGED_DEBUMP.equals(key)) {
mReplayGainUntaggedDeBump = settings.getInt(PrefKeys.REPLAYGAIN_UNTAGGED_DEBUMP, 150);
refreshReplayGainValues();
} else if (PrefKeys.VOLUME_ON_NOTIFICATION.equals(key)) {
mVolumeOnNotification = settings.getInt(PrefKeys.VOLUME_ON_NOTIFICATION, 50);
} else if (PrefKeys.VOLUME_DURING_DUCKING.equals(key)) {
mVolumeDuringDucking = settings.getInt(PrefKeys.VOLUME_DURING_DUCKING, 50);
refreshDuckingValues();
} else if (PrefKeys.ENABLE_READAHEAD.equals(key)) {
mReadaheadEnabled = settings.getBoolean(PrefKeys.ENABLE_READAHEAD, false);
@ -1004,7 +1004,9 @@ public final class PlaybackService extends Service
mTimeline.setFinishAction(finishAction(state));
if((toggled & FLAG_DUCKING) != 0) {
mMediaPlayer.setIsDucking((state & FLAG_DUCKING) != 0);
boolean isDucking = (state & FLAG_DUCKING) != 0;
mMediaPlayer.setIsDucking(isDucking);
mPreparedMediaPlayer.setIsDucking(isDucking);
}
}
@ -2037,9 +2039,13 @@ public final class PlaybackService extends Service
Log.d("VanillaMusic", "audio focus change: " + type);
switch (type) {
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
mDuckedLoss = true;
setFlag(FLAG_DUCKING);
break;
synchronized (mStateLock) {
mDuckedLoss = (mState & FLAG_PLAYING) != 0;
if(mDuckedLoss) {
setFlag(FLAG_DUCKING);
}
break;
}
case AudioManager.AUDIOFOCUS_LOSS:
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
mDuckedLoss = false;

View File

@ -66,5 +66,5 @@ public class PrefKeys {
public static final String ENABLE_READAHEAD = "enable_readahead";
public static final String USE_DARK_THEME = "use_dark_theme";
public static final String FILESYSTEM_BROWSE_START = "filesystem_browse_start";
public static final String VOLUME_ON_NOTIFICATION = "volume_on_notification";
public static final String VOLUME_DURING_DUCKING = "volume_during_ducking";
}

View File

@ -88,8 +88,8 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
} else if(PrefKeys.REPLAYGAIN_UNTAGGED_DEBUMP.equals(getKey())) {
String summary = (String)mContext.getResources().getText(R.string.replaygain_untagged_debump_summary);
return String.format("%s %.1fdB", summary, (value-150)/10f);
} else if (PrefKeys.VOLUME_ON_NOTIFICATION.equals(getKey())) {
String summary = mContext.getString(R.string.volume_on_notification_summary);
} else if (PrefKeys.VOLUME_DURING_DUCKING.equals(getKey())) {
String summary = mContext.getString(R.string.volume_during_ducking_summary);
return summary + " " + value + "%";
} else {
return String.format("%d%% (%+.1fdB)", value, 20 * Math.log10(Math.pow(value / 100.0, 3)));
@ -107,15 +107,13 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
SeekBar seekBar = (SeekBar)view.findViewById(R.id.seek_bar);
int maxValue;
switch (getKey()) {
case PrefKeys.SHAKE_THRESHOLD:
maxValue = 300;
break;
case PrefKeys.VOLUME_ON_NOTIFICATION:
maxValue = 100;
break;
default:
maxValue = 150;
String key = getKey();
if (PrefKeys.SHAKE_THRESHOLD.equals(key)) {
maxValue = 300;
} else if (PrefKeys.VOLUME_DURING_DUCKING.equals(key)) {
maxValue = 100;
} else {
maxValue = 150;
}
seekBar.setMax(maxValue);
@ -128,7 +126,7 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
@Override
protected void onDialogClosed(boolean positiveResult)
{
if(!positiveResult && PrefKeys.VOLUME_ON_NOTIFICATION.equals(getKey())) {
if(!positiveResult && PrefKeys.VOLUME_DURING_DUCKING.equals(getKey())) {
setValue(50);
}
notifyChanged();

View File

@ -155,5 +155,5 @@ public class VanillaMediaPlayer extends MediaPlayer {
setVolume(volume, volume);
}
}