diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index e890f03b7..bad6bdf0a 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -493,14 +493,9 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O barLeftVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - float leftVolume = 1.0f, rightVolume = 1.0f; - if (progress < 100) { - leftVolume = progress / 100.0f; - } - if (barRightVolume.getProgress() < 100) { - rightVolume = barRightVolume.getProgress() / 100.0f; - } - controller.setVolume(leftVolume, rightVolume); + controller.setVolume( + Converter.getVolumeFromPercentage(progress), + Converter.getVolumeFromPercentage(barRightVolume.getProgress())); } @Override @@ -514,14 +509,9 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O barRightVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - float leftVolume = 1.0f, rightVolume = 1.0f; - if (progress < 100) { - rightVolume = progress / 100.0f; - } - if (barLeftVolume.getProgress() < 100) { - leftVolume = barLeftVolume.getProgress() / 100.0f; - } - controller.setVolume(leftVolume, rightVolume); + controller.setVolume( + Converter.getVolumeFromPercentage(barLeftVolume.getProgress()), + Converter.getVolumeFromPercentage(progress)); } @Override diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index 6c0aff15e..293514ec7 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -29,6 +29,7 @@ import de.danoeh.antennapod.core.storage.APCleanupAlgorithm; import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm; import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm; import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm; +import de.danoeh.antennapod.core.util.Converter; /** * Provides access to preferences set by the user in the settings screen. A @@ -260,20 +261,12 @@ public class UserPreferences { public static float getLeftVolume() { int volume = prefs.getInt(PREF_LEFT_VOLUME, 100); - if(volume == 100) { - return 1.0f; - } else { - return (float) (1 - (Math.log(100 - volume) / Math.log(100))); - } + return Converter.getVolumeFromPercentage(volume); } public static float getRightVolume() { int volume = prefs.getInt(PREF_RIGHT_VOLUME, 100); - if(volume == 100) { - return 1.0f; - } else { - return (float) (1 - (Math.log(100 - volume) / Math.log(100))); - } + return Converter.getVolumeFromPercentage(volume); } public static boolean shouldPauseForFocusLoss() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java index 1b929b214..74fb9e709 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java @@ -118,5 +118,16 @@ public final class Converter { result += minutes; return result; } - + + /** + * 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))); + } }