Removed left/right volume controls

The setting does not work in our default player anyway and just
clutters the interface with yet another setting that nobody uses.
This commit is contained in:
ByteHamster 2021-07-29 21:37:34 +02:00
parent bc59d50804
commit 4e185f2895
8 changed files with 16 additions and 183 deletions
app/src/main
java/de/danoeh/antennapod/dialog
res/layout
core/src/main
java/de/danoeh/antennapod/core
res/values

@ -10,11 +10,9 @@ import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.playback.PlaybackController; import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.view.PlaybackSpeedSeekBar; import de.danoeh.antennapod.view.PlaybackSpeedSeekBar;
@ -63,11 +61,7 @@ public class PlaybackControlsDialog extends DialogFragment {
dialog = new AlertDialog.Builder(getContext()) dialog = new AlertDialog.Builder(getContext())
.setTitle(R.string.audio_controls) .setTitle(R.string.audio_controls)
.setView(R.layout.audio_controls) .setView(R.layout.audio_controls)
.setPositiveButton(R.string.close_label, (dialog1, which) -> { .setPositiveButton(R.string.close_label, null).create();
final SeekBar left = dialog.findViewById(R.id.volume_left);
final SeekBar right = dialog.findViewById(R.id.volume_right);
UserPreferences.setVolume(left.getProgress(), right.getProgress());
}).create();
return dialog; return dialog;
} }
@ -79,10 +73,6 @@ public class PlaybackControlsDialog extends DialogFragment {
speedSeekBar.setProgressChangedListener(speed speedSeekBar.setProgressChangedListener(speed
-> txtvPlaybackSpeed.setText(String.format(Locale.getDefault(), "%.2fx", speed))); -> txtvPlaybackSpeed.setText(String.format(Locale.getDefault(), "%.2fx", speed)));
final SeekBar barLeftVolume = dialog.findViewById(R.id.volume_left);
barLeftVolume.setProgress(UserPreferences.getLeftVolumePercentage());
final SeekBar barRightVolume = dialog.findViewById(R.id.volume_right);
barRightVolume.setProgress(UserPreferences.getRightVolumePercentage());
final CheckBox stereoToMono = dialog.findViewById(R.id.stereo_to_mono); final CheckBox stereoToMono = dialog.findViewById(R.id.stereo_to_mono);
stereoToMono.setChecked(UserPreferences.stereoToMono()); stereoToMono.setChecked(UserPreferences.stereoToMono());
if (controller != null && !controller.canDownmix()) { if (controller != null && !controller.canDownmix()) {
@ -91,10 +81,6 @@ public class PlaybackControlsDialog extends DialogFragment {
stereoToMono.setText(getString(R.string.stereo_to_mono) + " [" + sonicOnly + "]"); stereoToMono.setText(getString(R.string.stereo_to_mono) + " [" + sonicOnly + "]");
} }
if (UserPreferences.useExoplayer()) {
barRightVolume.setEnabled(false);
}
final CheckBox skipSilence = dialog.findViewById(R.id.skipSilence); final CheckBox skipSilence = dialog.findViewById(R.id.skipSilence);
skipSilence.setChecked(UserPreferences.isSkipSilence()); skipSilence.setChecked(UserPreferences.isSkipSilence());
if (!UserPreferences.useExoplayer()) { if (!UserPreferences.useExoplayer()) {
@ -106,39 +92,6 @@ public class PlaybackControlsDialog extends DialogFragment {
UserPreferences.setSkipSilence(isChecked); UserPreferences.setSkipSilence(isChecked);
controller.setSkipSilence(isChecked); controller.setSkipSilence(isChecked);
}); });
barLeftVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
controller.setVolume(
Converter.getVolumeFromPercentage(progress),
Converter.getVolumeFromPercentage(barRightVolume.getProgress()));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
barRightVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
controller.setVolume(
Converter.getVolumeFromPercentage(barLeftVolume.getProgress()),
Converter.getVolumeFromPercentage(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
stereoToMono.setOnCheckedChangeListener((buttonView, isChecked) -> { stereoToMono.setOnCheckedChangeListener((buttonView, isChecked) -> {
UserPreferences.stereoToMono(isChecked); UserPreferences.stereoToMono(isChecked);
if (controller != null) { if (controller != null) {

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView <ScrollView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"> android:padding="16dp">
<LinearLayout <LinearLayout
@ -17,7 +17,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone" android:visibility="gone"
android:layout_marginBottom="8dp"/> android:layout_marginBottom="8dp" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -27,9 +27,9 @@
<TextView <TextView
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@style/AntennaPod.TextView.ListItemPrimaryTitle"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/playback_speed" /> android:text="@string/playback_speed"
style="@style/AntennaPod.TextView.ListItemPrimaryTitle" />
<TextView <TextView
android:id="@+id/txtvPlaybackSpeed" android:id="@+id/txtvPlaybackSpeed"
@ -42,67 +42,14 @@
<de.danoeh.antennapod.view.PlaybackSpeedSeekBar <de.danoeh.antennapod.view.PlaybackSpeedSeekBar
android:id="@+id/speed_seek_bar" android:id="@+id/speed_seek_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginBottom="4dp"
style="@style/AntennaPod.TextView.ListItemPrimaryTitle"
android:text="@string/volume" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:id="@+id/txtvLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/left_short" />
<SeekBar
android:id="@+id/volume_left"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:id="@+id/txtvRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/right_short" />
<SeekBar
android:id="@+id/volume_right"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100" />
</LinearLayout>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
style="@style/AntennaPod.TextView.ListItemPrimaryTitle" android:text="@string/audio_effects"
android:text="@string/audio_effects" /> style="@style/AntennaPod.TextView.ListItemPrimaryTitle" />
<CheckBox <CheckBox
android:id="@+id/skipSilence" android:id="@+id/skipSilence"
@ -115,5 +62,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/stereo_to_mono" /> android:text="@string/stereo_to_mono" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

@ -8,7 +8,6 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
@ -40,7 +39,6 @@ import de.danoeh.antennapod.core.storage.ExceptFavoriteCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm; import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm; import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm; import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.model.feed.SortOrder; import de.danoeh.antennapod.model.feed.SortOrder;
import de.danoeh.antennapod.core.util.download.AutoUpdateManager; import de.danoeh.antennapod.core.util.download.AutoUpdateManager;
@ -471,24 +469,6 @@ public class UserPreferences {
return readPlaybackSpeedArray(prefs.getString(PREF_PLAYBACK_SPEED_ARRAY, null)); return readPlaybackSpeedArray(prefs.getString(PREF_PLAYBACK_SPEED_ARRAY, null));
} }
public static float getLeftVolume() {
int volume = prefs.getInt(PREF_LEFT_VOLUME, 100);
return Converter.getVolumeFromPercentage(volume);
}
public static float getRightVolume() {
int volume = prefs.getInt(PREF_RIGHT_VOLUME, 100);
return Converter.getVolumeFromPercentage(volume);
}
public static int getLeftVolumePercentage() {
return prefs.getInt(PREF_LEFT_VOLUME, 100);
}
public static int getRightVolumePercentage() {
return prefs.getInt(PREF_RIGHT_VOLUME, 100);
}
public static boolean shouldPauseForFocusLoss() { public static boolean shouldPauseForFocusLoss() {
return prefs.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false); return prefs.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
} }
@ -727,14 +707,6 @@ public class UserPreferences {
.apply(); .apply();
} }
public static void setVolume(@IntRange(from = 0, to = 100) int leftVolume,
@IntRange(from = 0, to = 100) int rightVolume) {
prefs.edit()
.putInt(PREF_LEFT_VOLUME, leftVolume)
.putInt(PREF_RIGHT_VOLUME, rightVolume)
.apply();
}
public static void setAutodownloadSelectedNetworks(String[] value) { public static void setAutodownloadSelectedNetworks(String[] value) {
prefs.edit() prefs.edit()
.putString(PREF_AUTODL_SELECTED_NETWORKS, TextUtils.join(",", value)) .putString(PREF_AUTODL_SELECTED_NETWORKS, TextUtils.join(",", value))

@ -322,10 +322,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
acquireWifiLockIfNecessary(); acquireWifiLockIfNecessary();
setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence()); setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence());
setVolume(1.0f, 1.0f);
float leftVolume = UserPreferences.getLeftVolume();
float rightVolume = UserPreferences.getRightVolume();
setVolume(leftVolume, rightVolume);
if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) { if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) {
int newPosition = RewindAfterPauseUtils.calculatePositionWithRewind( int newPosition = RewindAfterPauseUtils.calculatePositionWithRewind(
@ -891,16 +888,13 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
if (pausedBecauseOfTransientAudiofocusLoss) { // we paused => play now if (pausedBecauseOfTransientAudiofocusLoss) { // we paused => play now
resume(); resume();
} else { // we ducked => raise audio level back } else { // we ducked => raise audio level back
setVolumeSync(UserPreferences.getLeftVolume(), setVolumeSync(1.0f, 1.0f);
UserPreferences.getRightVolume());
} }
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
if (playerStatus == PlayerStatus.PLAYING) { if (playerStatus == PlayerStatus.PLAYING) {
if (!UserPreferences.shouldPauseForFocusLoss()) { if (!UserPreferences.shouldPauseForFocusLoss()) {
Log.d(TAG, "Lost audio focus temporarily. Ducking..."); Log.d(TAG, "Lost audio focus temporarily. Ducking...");
final float DUCK_FACTOR = 0.25f; setVolumeSync(0.25f, 0.25f);
setVolumeSync(DUCK_FACTOR * UserPreferences.getLeftVolume(),
DUCK_FACTOR * UserPreferences.getRightVolume());
pausedBecauseOfTransientAudiofocusLoss = false; pausedBecauseOfTransientAudiofocusLoss = false;
} else { } else {
Log.d(TAG, "Lost audio focus temporarily. Could duck, but won't, pausing..."); Log.d(TAG, "Lost audio focus temporarily. Could duck, but won't, pausing...");

@ -779,25 +779,19 @@ public class PlaybackService extends MediaBrowserServiceCompat {
final float[] multiplicators = {0.1f, 0.2f, 0.3f, 0.3f, 0.3f, 0.4f, 0.4f, 0.4f, 0.6f, 0.8f}; final float[] multiplicators = {0.1f, 0.2f, 0.3f, 0.3f, 0.3f, 0.4f, 0.4f, 0.4f, 0.6f, 0.8f};
float multiplicator = multiplicators[Math.max(0, (int) timeLeft / 1000)]; float multiplicator = multiplicators[Math.max(0, (int) timeLeft / 1000)];
Log.d(TAG, "onSleepTimerAlmostExpired: " + multiplicator); Log.d(TAG, "onSleepTimerAlmostExpired: " + multiplicator);
float leftVolume = multiplicator * UserPreferences.getLeftVolume(); mediaPlayer.setVolume(multiplicator, multiplicator);
float rightVolume = multiplicator * UserPreferences.getRightVolume();
mediaPlayer.setVolume(leftVolume, rightVolume);
} }
@Override @Override
public void onSleepTimerExpired() { public void onSleepTimerExpired() {
mediaPlayer.pause(true, true); mediaPlayer.pause(true, true);
float leftVolume = UserPreferences.getLeftVolume(); mediaPlayer.setVolume(1.0f, 1.0f);
float rightVolume = UserPreferences.getRightVolume();
mediaPlayer.setVolume(leftVolume, rightVolume);
sendNotificationBroadcast(NOTIFICATION_TYPE_SLEEPTIMER_UPDATE, 0); sendNotificationBroadcast(NOTIFICATION_TYPE_SLEEPTIMER_UPDATE, 0);
} }
@Override @Override
public void onSleepTimerReset() { public void onSleepTimerReset() {
float leftVolume = UserPreferences.getLeftVolume(); mediaPlayer.setVolume(1.0f, 1.0f);
float rightVolume = UserPreferences.getRightVolume();
mediaPlayer.setVolume(leftVolume, rightVolume);
} }
@Override @Override
@ -1705,10 +1699,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
mediaPlayer.setPlaybackParams(getCurrentPlaybackSpeed(), skipSilence); mediaPlayer.setPlaybackParams(getCurrentPlaybackSpeed(), skipSilence);
} }
public void setVolume(float leftVolume, float rightVolume) {
mediaPlayer.setVolume(leftVolume, rightVolume);
}
public float getCurrentPlaybackSpeed() { public float getCurrentPlaybackSpeed() {
if(mediaPlayer == null) { if(mediaPlayer == null) {
return 1.0f; return 1.0f;

@ -12,9 +12,6 @@ public final class Converter {
private Converter() { private Converter() {
} }
/** Logging tag. */
private static final String TAG = "Converter";
private static final int HOURS_MIL = 3600000; private static final int HOURS_MIL = 3600000;
private static final int MINUTES_MIL = 60000; private static final int MINUTES_MIL = 60000;
private static final int SECONDS_MIL = 1000; private static final int SECONDS_MIL = 1000;
@ -108,17 +105,4 @@ public final class Converter {
float hours = (float) time / 3600f; float hours = (float) time / 3600f;
return String.format(Locale.getDefault(), "%.1f ", hours) + context.getString(R.string.time_hours); return String.format(Locale.getDefault(), "%.1f ", hours) + context.getString(R.string.time_hours);
} }
/**
* Converts the volume as read as the progress from a SeekBar scaled to 100 and as saved in
* UserPreferences to the format taken by setVolume methods.
* @param progress integer between 0 to 100 taken from the SeekBar progress
* @return the appropriate volume as float taken by setVolume methods
*/
public static float getVolumeFromPercentage(int progress) {
if (progress == 100) {
return 1f;
}
return (float) (1 - (Math.log(101 - progress) / Math.log(101)));
}
} }

@ -496,12 +496,6 @@ public abstract class PlaybackController {
} }
} }
public void setVolume(float leftVolume, float rightVolume) {
if (playbackService != null) {
playbackService.setVolume(leftVolume, rightVolume);
}
}
public float getCurrentPlaybackSpeedMultiplier() { public float getCurrentPlaybackSpeedMultiplier() {
if (playbackService != null) { if (playbackService != null) {
return playbackService.getCurrentPlaybackSpeed(); return playbackService.getCurrentPlaybackSpeed();

@ -777,9 +777,6 @@
<!-- Audio controls --> <!-- Audio controls -->
<string name="audio_controls">Audio controls</string> <string name="audio_controls">Audio controls</string>
<string name="playback_speed">Playback Speed</string> <string name="playback_speed">Playback Speed</string>
<string name="volume">Volume</string>
<string name="left_short">L</string>
<string name="right_short">R</string>
<string name="audio_effects">Audio Effects</string> <string name="audio_effects">Audio Effects</string>
<string name="stereo_to_mono">Downmix: Stereo to mono</string> <string name="stereo_to_mono">Downmix: Stereo to mono</string>
<string name="sonic_only">Sonic only</string> <string name="sonic_only">Sonic only</string>