diff --git a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java
index 7a9ede8c5..b093bcd72 100644
--- a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java
@@ -129,7 +129,7 @@ public class PlaybackServiceMediaPlayerTest {
private Playable writeTestPlayable(String downloadUrl, String fileUrl) {
final Context c = getInstrumentation().getTargetContext();
Feed f = new Feed(0, null, "f", "l", "d", null, null, null, null, "i", null, null, "l", false);
- FeedPreferences prefs = new FeedPreferences(f.getId(), false, FeedPreferences.AutoDeleteAction.NO, null, null);
+ FeedPreferences prefs = new FeedPreferences(f.getId(), false, FeedPreferences.AutoDeleteAction.NO, FeedPreferences.VolumeReductionSetting.OFF, null, null);
f.setPreferences(prefs);
f.setItems(new ArrayList<>());
FeedItem i = new FeedItem(0, "t", "i", "l", new Date(), FeedItem.UNPLAYED, f);
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
index ea7687bc9..2ea06d08e 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
@@ -270,7 +270,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
url = URLChecker.prepareURL(url);
feed = new Feed(url, null);
if (username != null && password != null) {
- feed.setPreferences(new FeedPreferences(0, false, FeedPreferences.AutoDeleteAction.GLOBAL, username, password));
+ feed.setPreferences(new FeedPreferences(0, false, FeedPreferences.AutoDeleteAction.GLOBAL, FeedPreferences.VolumeReductionSetting.OFF, username, password));
}
String fileUrl = new File(getExternalCacheDir(),
FileNameGenerator.generateFileName(feed.getDownload_url())).toString();
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java
index 4fb3d90f5..e08020d9c 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java
@@ -38,10 +38,12 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
setupAutoDownloadPreference();
setupKeepUpdatedPreference();
setupAutoDeletePreference();
+ setupVolumeReductionPreferences();
setupAuthentificationPreference();
setupEpisodeFilterPreference();
updateAutoDeleteSummary();
+ updateVolumeReductionSummary();
updateAutoDownloadEnabled();
}).dispose();
}
@@ -114,6 +116,46 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
}
}
+ private void setupVolumeReductionPreferences() {
+ ListPreference volumeReductionPreference = (ListPreference) findPreference("volumeReduction");
+ volumeReductionPreference.setOnPreferenceChangeListener((preference, newValue) -> {
+ switch ((String) newValue) {
+ case "off":
+ feedPreferences.setVolumeReductionSetting(FeedPreferences.VolumeReductionSetting.OFF);
+ break;
+ case "light":
+ feedPreferences.setVolumeReductionSetting(FeedPreferences.VolumeReductionSetting.LIGHT);
+ break;
+ case "heavy":
+ feedPreferences.setVolumeReductionSetting(FeedPreferences.VolumeReductionSetting.HEAVY);
+ break;
+ }
+ feed.savePreferences();
+ updateVolumeReductionSummary();
+ // TODO maxbechtold Check if we can call setVolume for the PlaybackService, if running
+ return false;
+ });
+ }
+
+ private void updateVolumeReductionSummary() {
+ ListPreference volumeReductionPreference = (ListPreference) findPreference("volumeReduction");
+
+ switch (feedPreferences.getVolumeReductionSetting()) {
+ case OFF:
+ volumeReductionPreference.setSummary(R.string.feed_volume_reduction_off);
+ volumeReductionPreference.setValue("off");
+ break;
+ case LIGHT:
+ volumeReductionPreference.setSummary(R.string.feed_volume_reduction_light);
+ volumeReductionPreference.setValue("light");
+ break;
+ case HEAVY:
+ volumeReductionPreference.setSummary(R.string.feed_volume_reduction_heavy);
+ volumeReductionPreference.setValue("heavy");
+ break;
+ }
+ }
+
private void setupKeepUpdatedPreference() {
SwitchPreference pref = (SwitchPreference) findPreference("keepUpdated");
diff --git a/app/src/main/res/xml/feed_settings.xml b/app/src/main/res/xml/feed_settings.xml
index 5fd6b2038..f94b710e5 100644
--- a/app/src/main/res/xml/feed_settings.xml
+++ b/app/src/main/res/xml/feed_settings.xml
@@ -18,6 +18,14 @@
android:title="@string/auto_delete_label"
android:key="autoDelete"/>
+
+
0;
int autoDeleteActionIndex = cursor.getInt(indexAutoDeleteAction);
AutoDeleteAction autoDeleteAction = AutoDeleteAction.values()[autoDeleteActionIndex];
+ int volumeReductionIndex = cursor.getInt(indexVolumeReduction);
+ VolumeReductionSetting volumeReductionSetting = VolumeReductionSetting.values()[volumeReductionIndex];
String username = cursor.getString(indexUsername);
String password = cursor.getString(indexPassword);
String includeFilter = cursor.getString(indexIncludeFilter);
String excludeFilter = cursor.getString(indexExcludeFilter);
- return new FeedPreferences(feedId, autoDownload, autoRefresh, autoDeleteAction, username, password, new FeedFilter(includeFilter, excludeFilter));
+ return new FeedPreferences(feedId, autoDownload, autoRefresh, autoDeleteAction, volumeReductionSetting, username, password, new FeedFilter(includeFilter, excludeFilter));
}
/**
@@ -138,10 +150,18 @@ public class FeedPreferences {
return auto_delete_action;
}
+ public VolumeReductionSetting getVolumeReductionSetting() {
+ return volumeReductionSetting;
+ }
+
public void setAutoDeleteAction(AutoDeleteAction auto_delete_action) {
this.auto_delete_action = auto_delete_action;
}
+ public void setVolumeReductionSetting(VolumeReductionSetting volumeReductionSetting) {
+ this.volumeReductionSetting = volumeReductionSetting;
+ }
+
public boolean getCurrentAutoDelete() {
switch (auto_delete_action) {
case GLOBAL:
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
index 787d465d8..1b94bb3c3 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
@@ -764,7 +764,7 @@ public class DownloadService extends Service {
feed.setId(request.getFeedfileId());
feed.setDownloaded(true);
feed.setPreferences(new FeedPreferences(0, true, FeedPreferences.AutoDeleteAction.GLOBAL,
- request.getUsername(), request.getPassword()));
+ FeedPreferences.VolumeReductionSetting.OFF, request.getUsername(), request.getPassword()));
feed.setPageNr(request.getArguments().getInt(DownloadRequester.REQUEST_ARG_PAGE_NR, 0));
DownloadError reason = null;
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java
index 9c24e2f76..03704229b 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java
@@ -313,18 +313,10 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
UserPreferences.setPlaybackSpeed(String.valueOf(speed));
}
setPlaybackParams(speed, UserPreferences.isSkipSilence());
- // TODO MAX Here and everywhere else volume is adapted
- Playable playable = getPlayable();
- if (playable instanceof FeedMedia) {
- FeedMedia feedMedia = (FeedMedia) playable;
- FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
- // TODO MAX Check if this feed should have volume adjusted (e.g. louder than others)
-
-
- }
-
- setVolume(UserPreferences.getLeftVolume(), UserPreferences.getRightVolume());
+ float leftVolume = UserPreferences.getLeftVolume();
+ float rightVolume = UserPreferences.getRightVolume();
+ setVolume(leftVolume, rightVolume);
if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) {
int newPosition = RewindAfterPauseUtils.calculatePositionWithRewind(
@@ -344,8 +336,25 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
}
}
+ private float getVolumeReductionFactor() {
+ Playable playable = getPlayable();
+ if (playable instanceof FeedMedia) {
+ FeedMedia feedMedia = (FeedMedia) playable;
+ FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
+ FeedPreferences.VolumeReductionSetting volumeReductionSetting = preferences.getVolumeReductionSetting();
- /**
+ // TODO maxbechtold These numbers should be tested
+ if (volumeReductionSetting == FeedPreferences.VolumeReductionSetting.LIGHT) {
+ return 0.4f;
+ } else if (volumeReductionSetting == FeedPreferences.VolumeReductionSetting.HEAVY) {
+ return 0.2f;
+ }
+ }
+ return 1.0f;
+ }
+
+
+ /**
* Saves the current position and pauses playback. Note that, if audiofocus
* is abandoned, the lockscreen controls will also disapear.
*
@@ -681,6 +690,10 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
private void setVolumeSync(float volumeLeft, float volumeRight) {
playerLock.lock();
if (media != null && media.getMediaType() == MediaType.AUDIO) {
+ // TODO maxbechtold does not apply to currently playing episode
+ float reductionFactor = getVolumeReductionFactor();
+ volumeLeft *= reductionFactor;
+ volumeRight *= reductionFactor;
mediaPlayer.setVolume(volumeLeft, volumeRight);
Log.d(TAG, "Media player volume was set to " + volumeLeft + " " + volumeRight);
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java
index 306f8d104..1f6b430e0 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java
@@ -193,6 +193,7 @@ class DBUpgrader {
db.execSQL(sql);
}
if (oldVersion <= 17) {
+ // TODO maxbechtold Something like this for volume reduction
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ " ADD COLUMN " + PodDBAdapter.KEY_AUTO_DELETE_ACTION + " INTEGER DEFAULT 0");
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
index f7956372b..5fe18c3b4 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
@@ -103,6 +103,7 @@ public class PodDBAdapter {
public static final String KEY_AUTO_DOWNLOAD = "auto_download";
public static final String KEY_KEEP_UPDATED = "keep_updated";
public static final String KEY_AUTO_DELETE_ACTION = "auto_delete_action";
+ public static final String KEY_FEED_VOLUME_REDUCTION = "feed_volume_reduction";
public static final String KEY_PLAYED_DURATION = "played_duration";
public static final String KEY_USERNAME = "username";
public static final String KEY_PASSWORD = "password";
@@ -146,7 +147,8 @@ public class PodDBAdapter {
+ KEY_NEXT_PAGE_LINK + " TEXT,"
+ KEY_HIDE + " TEXT,"
+ KEY_LAST_UPDATE_FAILED + " INTEGER DEFAULT 0,"
- + KEY_AUTO_DELETE_ACTION + " INTEGER DEFAULT 0)";
+ + KEY_AUTO_DELETE_ACTION + " INTEGER DEFAULT 0,"
+ + KEY_FEED_VOLUME_REDUCTION + " INTEGER DEFAULT 0)";
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
@@ -242,6 +244,7 @@ public class PodDBAdapter {
TABLE_NAME_FEEDS + "." + KEY_HIDE,
TABLE_NAME_FEEDS + "." + KEY_LAST_UPDATE_FAILED,
TABLE_NAME_FEEDS + "." + KEY_AUTO_DELETE_ACTION,
+ TABLE_NAME_FEEDS + "." + KEY_FEED_VOLUME_REDUCTION,
TABLE_NAME_FEEDS + "." + KEY_INCLUDE_FILTER,
TABLE_NAME_FEEDS + "." + KEY_EXCLUDE_FILTER
};
@@ -404,6 +407,7 @@ public class PodDBAdapter {
values.put(KEY_AUTO_DOWNLOAD, prefs.getAutoDownload());
values.put(KEY_KEEP_UPDATED, prefs.getKeepUpdated());
values.put(KEY_AUTO_DELETE_ACTION, prefs.getAutoDeleteAction().ordinal());
+ values.put(KEY_FEED_VOLUME_REDUCTION, prefs.getVolumeReductionSetting().ordinal());
values.put(KEY_USERNAME, prefs.getUsername());
values.put(KEY_PASSWORD, prefs.getPassword());
values.put(KEY_INCLUDE_FILTER, prefs.getFilter().getIncludeFilter());
diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml
index 0eaf0e5e7..8190a39e2 100644
--- a/core/src/main/res/values/arrays.xml
+++ b/core/src/main/res/values/arrays.xml
@@ -13,6 +13,18 @@
- never
+
+ - @string/feed_volume_reduction_off
+ - @string/feed_volume_reduction_light
+ - @string/feed_volume_reduction_heavy
+
+
+
+ - off
+ - light
+ - heavy
+
+
- 0
- 15
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index a4084b76b..717d2302d 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -97,6 +97,10 @@
Apply to Previous Episodes
The new Auto Download setting will automatically be applied to new episodes.\nDo you also want to apply it to previously published episodes?
Auto Delete Episode
+ Volume Reduction
+ Off
+ Light
+ Heavy
\u0020parallel downloads
Global default
Always