diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-10-06 12:52:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-06 12:52:55 +0200 |
commit | de10ca9548f366b3aacc247cf1f5e2ad75f33d77 (patch) | |
tree | d1294771ebe4e22eecfcf9c1e37406264e6d07a8 | |
parent | 526c5744de0a539d7b375ed7f66b31e2147f3015 (diff) | |
parent | 138c29df0f9b0c8bcbfbcd74a31671b04cc06ff0 (diff) | |
download | AntennaPod-de10ca9548f366b3aacc247cf1f5e2ad75f33d77.zip |
Merge pull request #3415 from spacecowboy/per_feed_playbackspeed
Added per-feed playback speed setting
16 files changed, 190 insertions, 30 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index 795891273..8eb0b1e0b 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -12,6 +12,8 @@ import java.util.Locale; import java.util.concurrent.atomic.AtomicBoolean; import de.danoeh.antennapod.core.feed.MediaType; +import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.core.preferences.PlaybackSpeedHelper; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.dialog.VariableSpeedDialog; @@ -81,7 +83,7 @@ public class AudioplayerActivity extends MediaplayerInfoActivity { } float speed = 1.0f; if(controller.canSetPlaybackSpeed()) { - speed = UserPreferences.getPlaybackSpeed(); + speed = PlaybackSpeedHelper.getCurrentPlaybackSpeed(controller.getMedia()); } String speedStr = new DecimalFormat("0.00").format(speed); txtvPlaybackSpeed.setText(speedStr); @@ -105,7 +107,9 @@ public class AudioplayerActivity extends MediaplayerInfoActivity { String[] availableSpeeds = UserPreferences.getPlaybackSpeedArray(); DecimalFormatSymbols format = new DecimalFormatSymbols(Locale.US); format.setDecimalSeparator('.'); - String currentSpeed = new DecimalFormat("0.00", format).format(UserPreferences.getPlaybackSpeed()); + + float currentSpeedValue = controller.getCurrentPlaybackSpeedMultiplier(); + String currentSpeed = new DecimalFormat("0.00", format).format(currentSpeedValue); // Provide initial value in case the speed list has changed // out from under us @@ -127,6 +131,12 @@ public class AudioplayerActivity extends MediaplayerInfoActivity { break; } } + + try { + PlaybackPreferences.setCurrentlyPlayingTemporaryPlaybackSpeed(Float.parseFloat(newSpeed)); + } catch (NumberFormatException e) { + // Well this was awkward... + } UserPreferences.setPlaybackSpeed(newSpeed); controller.setPlaybackSpeed(Float.parseFloat(newSpeed)); onPositionObserverUpdate(); diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java index d742a1fd4..f53dbe57a 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java @@ -9,13 +9,14 @@ import android.widget.CheckBox; import android.widget.SeekBar; import android.widget.TextView; import com.afollestad.materialdialogs.MaterialDialog; +import java.util.Locale; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.preferences.PlaybackSpeedHelper; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.Converter; +import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.PlaybackController; -import java.util.Locale; - public class PlaybackControlsDialog extends DialogFragment { private static final float PLAYBACK_SPEED_STEP = 0.05f; private static final float DEFAULT_MIN_PLAYBACK_SPEED = 0.5f; @@ -206,9 +207,11 @@ public class PlaybackControlsDialog extends DialogFragment { } private float getCurrentSpeed() { - if (isPlayingVideo) { - return UserPreferences.getVideoPlaybackSpeed(); + Playable media = null; + if (controller != null) { + media = controller.getMedia(); } - return UserPreferences.getPlaybackSpeed(); + + return PlaybackSpeedHelper.getCurrentPlaybackSpeed(media); } } 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 b13521fa2..b745313aa 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java @@ -23,9 +23,16 @@ import io.reactivex.MaybeOnSubscribe; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Locale; + +import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL; public class FeedSettingsFragment extends PreferenceFragmentCompat { private static final CharSequence PREF_EPISODE_FILTER = "episodeFilter"; + private static final String PREF_FEED_PLAYBACK_SPEED = "feedPlaybackSpeed"; + private static final DecimalFormat decimalFormat = new DecimalFormat("0.00", DecimalFormatSymbols.getInstance(Locale.US)); private static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feedId"; private static final String TAG = "FeedSettingsFragment"; @@ -67,9 +74,11 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat { setupAutoDeletePreference(); setupAuthentificationPreference(); setupEpisodeFilterPreference(); + setupPlaybackSpeedPreference(); updateAutoDeleteSummary(); updateAutoDownloadEnabled(); + updatePlaybackSpeedPreference(); }, error -> Log.d(TAG, Log.getStackTraceString(error)), this::startPostponedEnterTransition); } @@ -97,6 +106,31 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat { } } + private void setupPlaybackSpeedPreference() { + ListPreference feedPlaybackSpeedPreference = findPreference(PREF_FEED_PLAYBACK_SPEED); + + String[] speeds = UserPreferences.getPlaybackSpeedArray(); + + String[] values = new String[speeds.length + 1]; + values[0] = decimalFormat.format(SPEED_USE_GLOBAL); + + String[] entries = new String[speeds.length + 1]; + entries[0] = getString(R.string.feed_auto_download_global); + + System.arraycopy(speeds, 0, values, 1, speeds.length); + System.arraycopy(speeds, 0, entries, 1, speeds.length); + + feedPlaybackSpeedPreference.setEntryValues(values); + feedPlaybackSpeedPreference.setEntries(entries); + + feedPlaybackSpeedPreference.setOnPreferenceChangeListener((preference, newValue) -> { + feedPreferences.setFeedPlaybackSpeed(Float.parseFloat((String) newValue)); + feed.savePreferences(); + updatePlaybackSpeedPreference(); + return false; + }); + } + private void setupEpisodeFilterPreference() { findPreference(PREF_EPISODE_FILTER).setOnPreferenceClickListener(preference -> { new EpisodeFilterDialog(getContext(), feedPreferences.getFilter()) { @@ -146,8 +180,15 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat { }); } + private void updatePlaybackSpeedPreference() { + ListPreference feedPlaybackSpeedPreference = findPreference(PREF_FEED_PLAYBACK_SPEED); + + float speedValue = feedPreferences.getFeedPlaybackSpeed(); + feedPlaybackSpeedPreference.setValue(decimalFormat.format(speedValue)); + } + private void updateAutoDeleteSummary() { - ListPreference autoDeletePreference = (ListPreference) findPreference("autoDelete"); + ListPreference autoDeletePreference = findPreference("autoDelete"); switch (feedPreferences.getAutoDeleteAction()) { case GLOBAL: @@ -221,7 +262,7 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat { } @Override - public void onConfirmButtonPressed(DialogInterface dialog) { + public void onConfirmButtonPressed(DialogInterface dialog) { DBWriter.setFeedsItemsAutoDownload(feed, autoDownload); } } 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 5634243da..b550669f3 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -44,6 +44,7 @@ import de.danoeh.antennapod.core.event.QueueEvent; import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.preferences.PlaybackSpeedHelper; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.DownloadService; import de.danoeh.antennapod.core.service.download.Downloader; @@ -635,8 +636,8 @@ public class QueueFragment extends Fragment { String info = queue.size() + getString(R.string.episodes_suffix); if(queue.size() > 0) { long timeLeft = 0; - float playbackSpeed = UserPreferences.getPlaybackSpeed(); for(FeedItem item : queue) { + float playbackSpeed = PlaybackSpeedHelper.getCurrentPlaybackSpeed(item.getMedia()); if(item.getMedia() != null) { timeLeft += (long) ((item.getMedia().getDuration() - item.getMedia().getPosition()) diff --git a/app/src/main/res/xml/feed_settings.xml b/app/src/main/res/xml/feed_settings.xml index 5fd6b2038..505248198 100644 --- a/app/src/main/res/xml/feed_settings.xml +++ b/app/src/main/res/xml/feed_settings.xml @@ -13,6 +13,11 @@ android:summary="@string/authentication_descr"/> <ListPreference + android:key="feedPlaybackSpeed" + android:title="@string/playback_speed" + android:summary="@string/pref_feed_playback_speed_sum"/> + + <ListPreference android:entries="@array/spnAutoDeleteItems" android:entryValues="@array/spnAutoDeleteValues" android:title="@string/auto_delete_label" diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java index 90fb6514b..8fdf2034f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java @@ -14,6 +14,8 @@ import de.danoeh.antennapod.core.storage.PodDBAdapter; */ public class FeedPreferences { + public static final float SPEED_USE_GLOBAL = -1; + @NonNull private FeedFilter filter; private long feedID; @@ -28,12 +30,13 @@ public class FeedPreferences { private AutoDeleteAction auto_delete_action; private String username; private String password; + private float feedPlaybackSpeed; public FeedPreferences(long feedID, boolean autoDownload, AutoDeleteAction auto_delete_action, String username, String password) { - this(feedID, autoDownload, true, auto_delete_action, username, password, new FeedFilter()); + this(feedID, autoDownload, true, auto_delete_action, username, password, new FeedFilter(), SPEED_USE_GLOBAL); } - private FeedPreferences(long feedID, boolean autoDownload, boolean keepUpdated, AutoDeleteAction auto_delete_action, String username, String password, @NonNull FeedFilter filter) { + private FeedPreferences(long feedID, boolean autoDownload, boolean keepUpdated, AutoDeleteAction auto_delete_action, String username, String password, @NonNull FeedFilter filter, float feedPlaybackSpeed) { this.feedID = feedID; this.autoDownload = autoDownload; this.keepUpdated = keepUpdated; @@ -41,6 +44,7 @@ public class FeedPreferences { this.username = username; this.password = password; this.filter = filter; + this.feedPlaybackSpeed = feedPlaybackSpeed; } public static FeedPreferences fromCursor(Cursor cursor) { @@ -52,6 +56,7 @@ public class FeedPreferences { int indexPassword = cursor.getColumnIndex(PodDBAdapter.KEY_PASSWORD); int indexIncludeFilter = cursor.getColumnIndex(PodDBAdapter.KEY_INCLUDE_FILTER); int indexExcludeFilter = cursor.getColumnIndex(PodDBAdapter.KEY_EXCLUDE_FILTER); + int indexFeedPlaybackSpeed = cursor.getColumnIndex(PodDBAdapter.KEY_FEED_PLAYBACK_SPEED); long feedId = cursor.getLong(indexId); boolean autoDownload = cursor.getInt(indexAutoDownload) > 0; @@ -62,7 +67,8 @@ public class FeedPreferences { 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)); + float feedPlaybackSpeed = cursor.getFloat(indexFeedPlaybackSpeed); + return new FeedPreferences(feedId, autoDownload, autoRefresh, autoDeleteAction, username, password, new FeedFilter(includeFilter, excludeFilter), feedPlaybackSpeed); } /** @@ -175,4 +181,12 @@ public class FeedPreferences { public void setPassword(String password) { this.password = password; } + + public float getFeedPlaybackSpeed() { + return feedPlaybackSpeed; + } + + public void setFeedPlaybackSpeed(float playbackSpeed) { + feedPlaybackSpeed = playbackSpeed; + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackPreferences.java index f2c0c8fe3..192674f0d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackPreferences.java @@ -11,6 +11,8 @@ import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.util.playback.Playable; +import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL; + /** * Provides access to preferences set by the playback service. A private * instance of this class must first be instantiated via createInstance() or @@ -55,6 +57,13 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference private static final String PREF_CURRENT_PLAYER_STATUS = "de.danoeh.antennapod.preferences.currentPlayerStatus"; /** + * A temporary playback speed which overrides the per-feed playback speed for the currently playing + * media. Considered unset if set to SPEED_USE_GLOBAL; + */ + private static final String PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED = "de.danoeh.antennapod.preferences.temporaryPlaybackSpeed"; + + + /** * Value of PREF_CURRENTLY_PLAYING_MEDIA if no media is playing. */ public static final long NO_MEDIA_PLAYING = -1; @@ -112,6 +121,10 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference return prefs.getInt(PREF_CURRENT_PLAYER_STATUS, PLAYER_STATUS_OTHER); } + public static float getCurrentlyPlayingTemporaryPlaybackSpeed() { + return prefs.getFloat(PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED, SPEED_USE_GLOBAL); + } + public static void writeNoMediaPlaying() { SharedPreferences.Editor editor = prefs.edit(); editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA, NO_MEDIA_PLAYING); @@ -154,6 +167,18 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference editor.apply(); } + public static void setCurrentlyPlayingTemporaryPlaybackSpeed(float speed) { + SharedPreferences.Editor editor = prefs.edit(); + editor.putFloat(PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED, speed); + editor.apply(); + } + + public static void clearCurrentlyPlayingTemporaryPlaybackSpeed() { + SharedPreferences.Editor editor = prefs.edit(); + editor.remove(PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED); + editor.apply(); + } + private static int getCurrentPlayerStatusAsInt(PlayerStatus playerStatus) { int playerStatusAsInt; switch (playerStatus) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackSpeedHelper.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackSpeedHelper.java new file mode 100644 index 000000000..d48e41c3b --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackSpeedHelper.java @@ -0,0 +1,41 @@ +package de.danoeh.antennapod.core.preferences; + +import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.core.feed.FeedItem; +import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.feed.MediaType; +import de.danoeh.antennapod.core.util.playback.Playable; + +import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL; + +public class PlaybackSpeedHelper { + + /** + * Returns the currently configured playback speed for the specified media. + */ + public static float getCurrentPlaybackSpeed(Playable media) { + float playbackSpeed = SPEED_USE_GLOBAL; + MediaType mediaType = null; + + if (media != null) { + mediaType = media.getMediaType(); + playbackSpeed = PlaybackPreferences.getCurrentlyPlayingTemporaryPlaybackSpeed(); + + if (playbackSpeed == SPEED_USE_GLOBAL && media instanceof FeedMedia) { + FeedItem item = ((FeedMedia) media).getItem(); + if (item != null) { + Feed feed = item.getFeed(); + if (feed != null) { + playbackSpeed = feed.getPreferences().getFeedPlaybackSpeed(); + } + } + } + } + + if (playbackSpeed == SPEED_USE_GLOBAL) { + playbackSpeed = UserPreferences.getPlaybackSpeed(mediaType); + } + + return playbackSpeed; + } +} 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 4a1d6f119..1987339ed 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 @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; +import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.service.download.ProxyConfig; import de.danoeh.antennapod.core.storage.APCleanupAlgorithm; @@ -321,7 +322,15 @@ public class UserPreferences { return prefs.getBoolean(PREF_DELETE_REMOVES_FROM_QUEUE, false); } - public static float getPlaybackSpeed() { + public static float getPlaybackSpeed(MediaType mediaType) { + if (mediaType == MediaType.VIDEO) { + return getVideoPlaybackSpeed(); + } else { + return getAudioPlaybackSpeed(); + } + } + + private static float getAudioPlaybackSpeed() { try { return Float.parseFloat(prefs.getString(PREF_PLAYBACK_SPEED, "1.00")); } catch (NumberFormatException e) { @@ -331,7 +340,7 @@ public class UserPreferences { } } - public static float getVideoPlaybackSpeed() { + private static float getVideoPlaybackSpeed() { try { return Float.parseFloat(prefs.getString(PREF_VIDEO_PLAYBACK_SPEED, "1.00")); } catch (NumberFormatException e) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java b/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java index 3cc8ebd7b..a34a1e2c3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java @@ -23,9 +23,8 @@ import com.bumptech.glide.request.RequestOptions; import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.core.R; -import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.glide.ApGlideSettings; -import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.core.preferences.PlaybackSpeedHelper; import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; import de.danoeh.antennapod.core.receiver.PlayerWidget; import de.danoeh.antennapod.core.service.playback.PlaybackService; @@ -148,9 +147,7 @@ public class PlayerWidgetJobService extends SafeJobIntentService { progressString = getProgressString(playbackService.getCurrentPosition(), playbackService.getDuration(), playbackService.getCurrentPlaybackSpeed()); } else { - float speed = media.getMediaType() == MediaType.VIDEO ? - UserPreferences.getVideoPlaybackSpeed() : UserPreferences.getPlaybackSpeed(); - progressString = getProgressString(media.getPosition(), media.getDuration(), speed); + progressString = getProgressString(media.getPosition(), media.getDuration(), PlaybackSpeedHelper.getCurrentPlaybackSpeed(media)); } if (progressString != 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 01c4df615..1584d29d2 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 @@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantLock; import de.danoeh.antennapod.core.feed.MediaType; +import de.danoeh.antennapod.core.preferences.PlaybackSpeedHelper; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.RewindAfterPauseUtils; import de.danoeh.antennapod.core.util.playback.AudioPlayer; @@ -242,6 +243,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { try { media.loadMetadata(); callback.onMediaChanged(false); + setPlaybackParams(PlaybackSpeedHelper.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence()); if (stream) { mediaPlayer.setDataSource(media.getStreamUrl()); } else if (media.getLocalMediaUrl() != null && new File(media.getLocalMediaUrl()).canRead()) { @@ -304,11 +306,8 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { Log.d(TAG, "Audiofocus successfully requested"); Log.d(TAG, "Resuming/Starting playback"); acquireWifiLockIfNecessary(); - if (media.getMediaType() == MediaType.VIDEO) { - setPlaybackParams(UserPreferences.getVideoPlaybackSpeed(), UserPreferences.isSkipSilence()); - } else { - setPlaybackParams(UserPreferences.getPlaybackSpeed(), UserPreferences.isSkipSilence()); - } + + setPlaybackParams(PlaybackSpeedHelper.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence()); setVolume(UserPreferences.getLeftVolume(), UserPreferences.getRightVolume()); if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 2eb9c92e4..848eacbd6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -959,6 +959,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { */ private void onPostPlayback(final Playable playable, boolean ended, boolean skipped, boolean playingNext) { + PlaybackPreferences.clearCurrentlyPlayingTemporaryPlaybackSpeed(); if (playable == null) { Log.e(TAG, "Cannot do post-playback processing: media was null"); return; 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..575b8d2ac 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 @@ -8,6 +8,8 @@ import android.util.Log; import de.danoeh.antennapod.core.feed.FeedItem; +import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL; + class DBUpgrader { /** * Upgrades the given database to a new schema version @@ -288,6 +290,10 @@ class DBUpgrader { db.execSQL("DROP TABLE " + PodDBAdapter.TABLE_NAME_FEED_IMAGES); } + if (oldVersion < 1070400) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + + " ADD COLUMN " + PodDBAdapter.KEY_FEED_PLAYBACK_SPEED + " REAL DEFAULT " + SPEED_USE_GLOBAL); + } } } 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 978f62395..5feedcebf 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 @@ -36,6 +36,8 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.DownloadStatus; import de.danoeh.antennapod.core.util.LongIntMap; +import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL; + // TODO Remove media column from feeditem table /** @@ -104,6 +106,7 @@ public class PodDBAdapter { public static final String KEY_LAST_PLAYED_TIME = "last_played_time"; public static final String KEY_INCLUDE_FILTER = "include_filter"; public static final String KEY_EXCLUDE_FILTER = "exclude_filter"; + public static final String KEY_FEED_PLAYBACK_SPEED = "feed_playback_speed"; // Table names static final String TABLE_NAME_FEEDS = "Feeds"; @@ -136,7 +139,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_PLAYBACK_SPEED + " REAL DEFAULT " + SPEED_USE_GLOBAL + ")"; private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE " + TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE @@ -157,7 +161,7 @@ public class PodDBAdapter { + KEY_FEEDITEM + " INTEGER," + KEY_PLAYED_DURATION + " INTEGER," + KEY_HAS_EMBEDDED_PICTURE + " INTEGER," - + KEY_LAST_PLAYED_TIME + " INTEGER)"; + + KEY_LAST_PLAYED_TIME + " INTEGER" + ")"; private static final String CREATE_TABLE_DOWNLOAD_LOG = "CREATE TABLE " + TABLE_NAME_DOWNLOAD_LOG + " (" + TABLE_PRIMARY_KEY + KEY_FEEDFILE @@ -233,7 +237,8 @@ public class PodDBAdapter { TABLE_NAME_FEEDS + "." + KEY_LAST_UPDATE_FAILED, TABLE_NAME_FEEDS + "." + KEY_AUTO_DELETE_ACTION, TABLE_NAME_FEEDS + "." + KEY_INCLUDE_FILTER, - TABLE_NAME_FEEDS + "." + KEY_EXCLUDE_FILTER + TABLE_NAME_FEEDS + "." + KEY_EXCLUDE_FILTER, + TABLE_NAME_FEEDS + "." + KEY_FEED_PLAYBACK_SPEED }; /** @@ -398,6 +403,7 @@ public class PodDBAdapter { values.put(KEY_PASSWORD, prefs.getPassword()); values.put(KEY_INCLUDE_FILTER, prefs.getFilter().getIncludeFilter()); values.put(KEY_EXCLUDE_FILTER, prefs.getFilter().getExcludeFilter()); + values.put(KEY_FEED_PLAYBACK_SPEED, prefs.getFeedPlaybackSpeed()); db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?", new String[]{String.valueOf(prefs.getFeedID())}); } @@ -1435,7 +1441,7 @@ public class PodDBAdapter { */ private static class PodDBHelper extends SQLiteOpenHelper { - private static final int VERSION = 1060596; + private static final int VERSION = 1070400; private final Context context; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index 5ce0e715e..39888428f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -29,6 +29,7 @@ import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.core.preferences.PlaybackSpeedHelper; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer; @@ -714,7 +715,7 @@ public class PlaybackController { if (playbackService != null && canSetPlaybackSpeed()) { return playbackService.getCurrentPlaybackSpeed(); } else { - return -1; + return PlaybackSpeedHelper.getCurrentPlaybackSpeed(getMedia()); } } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index adf938d75..0d61e30cd 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -426,6 +426,7 @@ <string name="pref_gpodnet_notifications_sum">This setting does not apply to authentication errors.</string> <string name="pref_playback_speed_title">Playback Speeds</string> <string name="pref_playback_speed_sum">Customize the speeds available for variable speed audio playback</string> + <string name="pref_feed_playback_speed_sum">The speed to use when starting audio playback for episodes in this feed</string> <string name="pref_playback_time_respects_speed_title">Adjust media info to playback speed</string> <string name="pref_playback_time_respects_speed_sum">Displayed position and duration are adapted to playback speed</string> <string name="pref_fast_forward">Fast Forward Skip Time</string> |