summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java2
-rw-r--r--app/src/main/java/de/danoeh/antennapod/preferences/VolumeAdaptationPreference.java27
-rw-r--r--app/src/main/res/xml/feed_settings.xml2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java19
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/Converter.java8
-rw-r--r--core/src/test/java/de/danoeh/antennapod/core/feed/VolumeAdaptionSettingTest.java13
-rw-r--r--model/src/main/java/de/danoeh/antennapod/model/feed/VolumeAdaptionSetting.java30
-rw-r--r--ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoActivity.java4
8 files changed, 94 insertions, 11 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java
index 1a2b6438f..003ee23db 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java
@@ -491,7 +491,7 @@ public class QueueFragment extends Fragment implements MaterialToolbar.OnMenuIte
}
info += " • ";
info += getString(R.string.time_left_label);
- info += Converter.getDurationStringLocalized(getActivity(), timeLeft);
+ info += Converter.getDurationStringLocalized(getResources(), timeLeft, false);
}
infoBar.setText(info);
}
diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/VolumeAdaptationPreference.java b/app/src/main/java/de/danoeh/antennapod/preferences/VolumeAdaptationPreference.java
new file mode 100644
index 000000000..584b7d90e
--- /dev/null
+++ b/app/src/main/java/de/danoeh/antennapod/preferences/VolumeAdaptationPreference.java
@@ -0,0 +1,27 @@
+package de.danoeh.antennapod.preferences;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+import java.util.Arrays;
+
+import de.danoeh.antennapod.model.feed.VolumeAdaptionSetting;
+
+public class VolumeAdaptationPreference extends MaterialListPreference {
+ public VolumeAdaptationPreference(Context context) {
+ super(context);
+ }
+
+ public VolumeAdaptationPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public CharSequence[] getEntries() {
+ if (VolumeAdaptionSetting.isBoostSupported()) {
+ return super.getEntries();
+ } else {
+ return Arrays.copyOfRange(super.getEntries(), 0, 3);
+ }
+ }
+}
diff --git a/app/src/main/res/xml/feed_settings.xml b/app/src/main/res/xml/feed_settings.xml
index fb9e2e425..b322217ad 100644
--- a/app/src/main/res/xml/feed_settings.xml
+++ b/app/src/main/res/xml/feed_settings.xml
@@ -48,7 +48,7 @@
android:summary="@string/global_default"
android:title="@string/auto_delete_label" />
- <de.danoeh.antennapod.preferences.MaterialListPreference
+ <de.danoeh.antennapod.preferences.VolumeAdaptationPreference
android:defaultValue="off"
android:entries="@array/spnVolumeAdaptationItems"
android:entryValues="@array/spnVolumeAdaptationValues"
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java
index 79cd97fd2..1900ed7f2 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java
@@ -7,6 +7,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.SurfaceHolder;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.core.util.Consumer;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.DefaultLoadControl;
@@ -37,6 +38,7 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.R;
+import de.danoeh.antennapod.model.feed.VolumeAdaptionSetting;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
import de.danoeh.antennapod.core.service.download.HttpCredentialEncoder;
@@ -69,7 +71,8 @@ public class ExoPlayerWrapper {
private PlaybackParameters playbackParameters;
private DefaultTrackSelector trackSelector;
- private LoudnessEnhancer loudnessEnhancer;
+ @Nullable
+ private LoudnessEnhancer loudnessEnhancer = null;
ExoPlayerWrapper(Context context) {
this.context = context;
@@ -247,11 +250,15 @@ public class ExoPlayerWrapper {
public void setVolume(float v, float v1) {
if (v > 1) {
exoPlayer.setVolume(1f);
- loudnessEnhancer.setEnabled(true);
- loudnessEnhancer.setTargetGain((int) (1000 * (v - 1)));
+ if (loudnessEnhancer != null) {
+ loudnessEnhancer.setEnabled(true);
+ loudnessEnhancer.setTargetGain((int) (1000 * (v - 1)));
+ }
} else {
exoPlayer.setVolume(v);
- loudnessEnhancer.setEnabled(false);
+ if (loudnessEnhancer != null) {
+ loudnessEnhancer.setEnabled(false);
+ }
}
}
@@ -354,6 +361,10 @@ public class ExoPlayerWrapper {
}
private void initLoudnessEnhancer(int audioStreamId) {
+ if (!VolumeAdaptionSetting.isBoostSupported()) {
+ return;
+ }
+
LoudnessEnhancer newEnhancer = new LoudnessEnhancer(audioStreamId);
LoudnessEnhancer oldEnhancer = this.loudnessEnhancer;
if (oldEnhancer != null) {
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 d9c4a5098..30464969b 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
@@ -83,14 +83,16 @@ public final class Converter {
* Converts milliseconds to a localized string containing hours and minutes.
*/
public static String getDurationStringLocalized(Context context, long duration) {
- return getDurationStringLocalized(context.getResources(), duration);
+ return getDurationStringLocalized(context.getResources(), duration, false);
}
- public static String getDurationStringLocalized(Resources resources, long duration) {
+ public static String getDurationStringLocalized(Resources resources, long duration, boolean includeDays) {
String result = "";
int h = (int) (duration / HOURS_MIL);
int d = h / 24;
- if (d > 0) {
+ if (!includeDays) {
+ d = 0;
+ } else if (d > 0) {
String days = resources.getQuantityString(R.plurals.time_days_quantified, d, d);
result += days.replace(" ", "\u00A0") + " ";
h -= d * 24;
diff --git a/core/src/test/java/de/danoeh/antennapod/core/feed/VolumeAdaptionSettingTest.java b/core/src/test/java/de/danoeh/antennapod/core/feed/VolumeAdaptionSettingTest.java
index 30767bdc8..966351a5e 100644
--- a/core/src/test/java/de/danoeh/antennapod/core/feed/VolumeAdaptionSettingTest.java
+++ b/core/src/test/java/de/danoeh/antennapod/core/feed/VolumeAdaptionSettingTest.java
@@ -1,6 +1,9 @@
package de.danoeh.antennapod.core.feed;
import de.danoeh.antennapod.model.feed.VolumeAdaptionSetting;
+
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
@@ -11,6 +14,16 @@ import static org.junit.Assert.assertTrue;
public class VolumeAdaptionSettingTest {
+ @Before
+ public void setUp() throws Exception {
+ VolumeAdaptionSetting.setBoostSupported(false);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ VolumeAdaptionSetting.setBoostSupported(null);
+ }
+
@Test
public void mapOffToInteger() {
VolumeAdaptionSetting setting = VolumeAdaptionSetting.OFF;
diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/VolumeAdaptionSetting.java b/model/src/main/java/de/danoeh/antennapod/model/feed/VolumeAdaptionSetting.java
index e71c5ad36..a9b1089f2 100644
--- a/model/src/main/java/de/danoeh/antennapod/model/feed/VolumeAdaptionSetting.java
+++ b/model/src/main/java/de/danoeh/antennapod/model/feed/VolumeAdaptionSetting.java
@@ -1,5 +1,10 @@
package de.danoeh.antennapod.model.feed;
+import android.media.audiofx.AudioEffect;
+
+import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
+
public enum VolumeAdaptionSetting {
OFF(0, 1.0f),
LIGHT_REDUCTION(1, 0.5f),
@@ -32,4 +37,29 @@ public enum VolumeAdaptionSetting {
public float getAdaptionFactor() {
return adaptionFactor;
}
+
+ @Nullable
+ private static Boolean boostSupported = null;
+
+ public static boolean isBoostSupported() {
+ if (boostSupported != null) {
+ return boostSupported;
+ }
+ final AudioEffect.Descriptor[] audioEffects = AudioEffect.queryEffects();
+ if (audioEffects != null) {
+ for (AudioEffect.Descriptor effect : audioEffects) {
+ if (effect.type.equals(AudioEffect.EFFECT_TYPE_LOUDNESS_ENHANCER)) {
+ boostSupported = true;
+ return boostSupported;
+ }
+ }
+ }
+ boostSupported = false;
+ return boostSupported;
+ }
+
+ @VisibleForTesting
+ public static void setBoostSupported(@Nullable Boolean boostSupported) {
+ VolumeAdaptionSetting.boostSupported = boostSupported;
+ }
}
diff --git a/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoActivity.java b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoActivity.java
index 69ce8373a..758eaeac7 100644
--- a/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoActivity.java
+++ b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoActivity.java
@@ -221,7 +221,7 @@ public class EchoActivity extends AppCompatActivity {
dec31.get(Calendar.DAY_OF_YEAR) - Calendar.getInstance().get(Calendar.DAY_OF_YEAR) + 1);
long secondsPerDay = queueSecondsLeft / daysUntilNextYear;
String timePerDay = Converter.getDurationStringLocalized(
- getLocalizedResources(this, getEchoLanguage()), secondsPerDay * 1000);
+ getLocalizedResources(this, getEchoLanguage()), secondsPerDay * 1000, true);
double hoursPerDay = (double) (secondsPerDay / 3600);
int nextYear = RELEASE_YEAR + 1;
if (hoursPerDay < 1.5) {
@@ -249,7 +249,7 @@ public class EchoActivity extends AppCompatActivity {
}
viewBinding.smallLabel.setText(getString(R.string.echo_listened_after_time,
Converter.getDurationStringLocalized(
- getLocalizedResources(this, getEchoLanguage()), timeBetweenReleaseAndPlay)));
+ getLocalizedResources(this, getEchoLanguage()), timeBetweenReleaseAndPlay, true)));
currentDrawable = new RotatingSquaresScreen(this);
break;
case 4: