Added option to disable audio ducking.
This commit is contained in:
parent
3596d08b8b
commit
869b935bf6
4 changed files with 38 additions and 8 deletions
|
|
@ -55,6 +55,8 @@ import java.lang.ref.WeakReference;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import hugo.weaving.DebugLog;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid), Andrew Neal
|
||||
*/
|
||||
|
|
@ -115,6 +117,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
private int nextPosition = -1;
|
||||
private int shuffleMode;
|
||||
private int repeatMode;
|
||||
private boolean audioDucking;
|
||||
private boolean pausedByTransientLossOfFocus;
|
||||
private boolean receiversAndRemoteControlClientRegistered;
|
||||
private PlayingNotificationHelper playingNotificationHelper;
|
||||
|
|
@ -162,6 +165,8 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
|
||||
wakeLock.setReferenceCounted(false);
|
||||
|
||||
audioDucking = PreferenceUtil.getInstance(this).audioDucking();
|
||||
|
||||
musicPlayerHandlerThread = new HandlerThread("PlaybackHandler");
|
||||
musicPlayerHandlerThread.start();
|
||||
playerHandler = new PlaybackHandler(this, musicPlayerHandlerThread.getLooper());
|
||||
|
|
@ -987,6 +992,9 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
switch (key) {
|
||||
case PreferenceUtil.AUDIO_DUCKING:
|
||||
audioDucking = sharedPreferences.getBoolean(key, true);
|
||||
break;
|
||||
case PreferenceUtil.GAPLESS_PLAYBACK:
|
||||
if (sharedPreferences.getBoolean(key, false)) {
|
||||
prepareNext();
|
||||
|
|
@ -1025,6 +1033,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
mService = new WeakReference<>(service);
|
||||
}
|
||||
|
||||
@DebugLog
|
||||
@Override
|
||||
public void handleMessage(@NonNull final Message msg) {
|
||||
final MusicService service = mService.get();
|
||||
|
|
@ -1034,21 +1043,29 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
|
||||
switch (msg.what) {
|
||||
case DUCK:
|
||||
if (service.audioDucking) {
|
||||
currentDuckVolume -= .05f;
|
||||
if (currentDuckVolume > .2f) {
|
||||
sendEmptyMessageDelayed(DUCK, 10);
|
||||
} else {
|
||||
currentDuckVolume = .2f;
|
||||
}
|
||||
} else {
|
||||
currentDuckVolume = 1f;
|
||||
}
|
||||
service.playback.setVolume(currentDuckVolume);
|
||||
break;
|
||||
|
||||
case UNDUCK:
|
||||
if (service.audioDucking) {
|
||||
currentDuckVolume += .03f;
|
||||
if (currentDuckVolume < 1.0f) {
|
||||
if (currentDuckVolume < 1f) {
|
||||
sendEmptyMessageDelayed(UNDUCK, 10);
|
||||
} else {
|
||||
currentDuckVolume = 1.0f;
|
||||
currentDuckVolume = 1f;
|
||||
}
|
||||
} else {
|
||||
currentDuckVolume = 1f;
|
||||
}
|
||||
service.playback.setVolume(currentDuckVolume);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ public final class PreferenceUtil {
|
|||
|
||||
public static final String COLORED_NOTIFICATION = "colored_notification";
|
||||
|
||||
public static final String AUDIO_DUCKING = "audio_ducking";
|
||||
public static final String GAPLESS_PLAYBACK = "gapless_playback";
|
||||
|
||||
public static final String LAST_ADDED_CUTOFF_TIMESTAMP = "last_added_cutoff_timestamp";
|
||||
|
|
@ -134,6 +135,10 @@ public final class PreferenceUtil {
|
|||
return mPreferences.getBoolean(GAPLESS_PLAYBACK, false);
|
||||
}
|
||||
|
||||
public final boolean audioDucking() {
|
||||
return mPreferences.getBoolean(AUDIO_DUCKING, true);
|
||||
}
|
||||
|
||||
public final boolean albumArtOnLockscreen() {
|
||||
return mPreferences.getBoolean(ALBUM_ART_ON_LOCKSCREEN, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@
|
|||
<string name="pref_title_alternative_progress_slider_now_playing">Alternative progress slider</string>
|
||||
<string name="pref_title_playback_controller_card_now_playing">Show card below playback controls</string>
|
||||
<string name="pref_title_colored_playback_controls_now_playing">Colored playback controls</string>
|
||||
<string name="pref_title_audio_ducking">Reduce volume on focus loss</string>
|
||||
<string name="no_equalizer">No equalizer found.</string>
|
||||
<string name="no_audio_ID">"Play a song first, then try again."</string>
|
||||
<string name="delete_action">Delete</string>
|
||||
|
|
@ -166,6 +167,7 @@
|
|||
<string name="pref_summary_ignore_media_store_artwork">Can increase the album cover quality but causes slower image loading times. Only enable this if you have problems with low resolution artworks.</string>
|
||||
<string name="pref_summary_colored_playback_controls_now_playing">Colors play/pause, shuffle and repeat as well as the progress slider in the album cover\u2019s vibrant color.</string>
|
||||
<string name="pref_summary_colored_navigation_bar">Colors the navigation bar in the primary color.</string>
|
||||
<string name="pref_summary_audio_ducking">Notifications, navigation etc.</string>
|
||||
<string name="could_not_download_album_cover">"Couldn\u2019t download a matching album cover."</string>
|
||||
<string name="search_hint">Search your library…</string>
|
||||
<string name="rescanning_media">Rescanning media…</string>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,12 @@
|
|||
|
||||
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_audio">
|
||||
|
||||
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="audio_ducking"
|
||||
android:summary="@string/pref_summary_audio_ducking"
|
||||
android:title="@string/pref_title_audio_ducking" />
|
||||
|
||||
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="gapless_playback"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue