diff options
author | ByteHamster <info@bytehamster.com> | 2019-02-01 16:25:20 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2019-02-01 16:25:20 +0100 |
commit | abe68ec7bded95f39116fa52e099ac5be3f30c03 (patch) | |
tree | 5231f84d6b282b80ac26a3f310de5d7b9b6afccf /core/src/main/java | |
parent | 56a72088591ce1909b77baef53cd1a54b06d68cb (diff) | |
parent | 73bb2f712ebc06423aecf115c40668b2c86f8c3b (diff) | |
download | AntennaPod-abe68ec7bded95f39116fa52e099ac5be3f30c03.zip |
Merge remote-tracking branch 'upstream/develop' into auto_download_12_hour_option_2685
Diffstat (limited to 'core/src/main/java')
12 files changed, 142 insertions, 88 deletions
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 95f206a63..1feecd849 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 @@ -100,10 +100,13 @@ public class UserPreferences { // Other private static final String PREF_DATA_FOLDER = "prefDataFolder"; public static final String PREF_IMAGE_CACHE_SIZE = "prefImageCacheSize"; + public static final String PREF_DELETE_REMOVES_FROM_QUEUE = "prefDeleteRemovesFromQueue"; // Mediaplayer public static final String PREF_MEDIA_PLAYER = "prefMediaPlayer"; + public static final String PREF_MEDIA_PLAYER_EXOPLAYER = "exoplayer"; private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed"; + public static final String PREF_PLAYBACK_SKIP_SILENCE = "prefSkipSilence"; private static final String PREF_FAST_FORWARD_SECS = "prefFastForwardSecs"; private static final String PREF_REWIND_SECS = "prefRewindSecs"; private static final String PREF_QUEUE_LOCKED = "prefQueueLocked"; @@ -309,6 +312,10 @@ public class UserPreferences { return Integer.parseInt(prefs.getString(PREF_SMART_MARK_AS_PLAYED_SECS, "30")); } + public static boolean shouldDeleteRemoveFromQueue() { + return prefs.getBoolean(PREF_DELETE_REMOVES_FROM_QUEUE, false); + } + public static boolean isAutoFlattr() { return prefs.getBoolean(PREF_AUTO_FLATTR, false); } @@ -317,6 +324,10 @@ public class UserPreferences { return prefs.getString(PREF_PLAYBACK_SPEED, "1.00"); } + public static boolean isSkipSilence() { + return prefs.getBoolean(PREF_PLAYBACK_SKIP_SILENCE, false); + } + public static String[] getPlaybackSpeedArray() { return readPlaybackSpeedArray(prefs.getString(PREF_PLAYBACK_SPEED_ARRAY, null)); } @@ -503,6 +514,12 @@ public class UserPreferences { .apply(); } + public static void setSkipSilence(boolean skipSilence) { + prefs.edit() + .putBoolean(PREF_PLAYBACK_SKIP_SILENCE, skipSilence) + .apply(); + } + public static void setPlaybackSpeedArray(String[] speeds) { JSONArray jsonArray = new JSONArray(); for (String speed : speeds) { @@ -647,7 +664,7 @@ public class UserPreferences { } public static boolean useExoplayer() { - return prefs.getString(PREF_MEDIA_PLAYER, "sonic").equals("exoplayer"); + return prefs.getString(PREF_MEDIA_PLAYER, "sonic").equals(PREF_MEDIA_PLAYER_EXOPLAYER); } public static void enableSonic() { 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 e1d87e1d5..281bd064b 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 @@ -25,7 +25,6 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.util.Util; import org.antennapod.audio.MediaPlayer; - import de.danoeh.antennapod.core.util.playback.IPlayer; @@ -43,7 +42,7 @@ public class ExoPlayerWrapper implements IPlayer { } private SimpleExoPlayer createPlayer() { - SimpleExoPlayer p = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(mContext), + SimpleExoPlayer p = ExoPlayerFactory.newSimpleInstance(mContext, new DefaultRenderersFactory(mContext), new DefaultTrackSelector(), new DefaultLoadControl()); p.setSeekParameters(SeekParameters.PREVIOUS_SYNC); p.addListener(new Player.EventListener() { @@ -192,9 +191,9 @@ public class ExoPlayerWrapper implements IPlayer { } @Override - public void setPlaybackSpeed(float v) { + public void setPlaybackParams(float speed, boolean skipSilence) { PlaybackParameters params = mExoPlayer.getPlaybackParameters(); - mExoPlayer.setPlaybackParameters(new PlaybackParameters(v, params.pitch)); + mExoPlayer.setPlaybackParameters(new PlaybackParameters(speed, params.pitch, skipSilence)); } @Override 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 c7948b157..9274b9a49 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 @@ -236,7 +236,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { Log.e(TAG, Log.getStackTraceString(e)); UserPreferences.setPlaybackSpeed(String.valueOf(speed)); } - setSpeed(speed); + setPlaybackParams(speed, UserPreferences.isSkipSilence()); setVolume(UserPreferences.getLeftVolume(), UserPreferences.getRightVolume()); if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) { @@ -537,14 +537,14 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { * Sets the playback speed. * This method is executed on the caller's thread. */ - private void setSpeedSync(float speed) { + private void setSpeedSyncAndSkipSilence(float speed, boolean skipSilence) { playerLock.lock(); if (media != null && media.getMediaType() == MediaType.AUDIO) { if (mediaPlayer.canSetSpeed()) { - mediaPlayer.setPlaybackSpeed(speed); Log.d(TAG, "Playback speed was set to " + speed); callback.playbackSpeedChanged(speed); } + mediaPlayer.setPlaybackParams(speed, skipSilence); } playerLock.unlock(); } @@ -554,8 +554,8 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { * This method is executed on an internal executor service. */ @Override - public void setSpeed(final float speed) { - executor.submit(() -> setSpeedSync(speed)); + public void setPlaybackParams(final float speed, final boolean skipSilence) { + executor.submit(() -> setSpeedSyncAndSkipSilence(speed, skipSilence)); } /** @@ -991,7 +991,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { private final MediaPlayer.OnErrorListener audioErrorListener = (mp, what, extra) -> { - if(mp.canFallback()) { + if(mp != null && mp.canFallback()) { mp.fallback(); return true; } else { 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 aea043a91..66cf7d244 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 @@ -1629,7 +1629,11 @@ public class PlaybackService extends MediaBrowserServiceCompat { } public void setSpeed(float speed) { - mediaPlayer.setSpeed(speed); + mediaPlayer.setPlaybackParams(speed, UserPreferences.isSkipSilence()); + } + + public void skipSilence(boolean skipSilence) { + mediaPlayer.setPlaybackParams(getCurrentPlaybackSpeed(), skipSilence); } public void setVolume(float leftVolume, float rightVolume) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java index a2481b801..b8198fa63 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java @@ -148,10 +148,12 @@ public abstract class PlaybackServiceMediaPlayer { public abstract boolean canSetSpeed(); /** - * Sets the playback speed. + * Sets the playback parameters. + * - Speed + * - SkipSilence (ExoPlayer only) * This method is executed on an internal executor service. */ - public abstract void setSpeed(float speed); + public abstract void setPlaybackParams(final float speed, final boolean skipSilence); /** * Returns the current playback speed. If the playback speed could not be retrieved, 1 is returned. diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index bbe6145ea..ab55bd3c0 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -7,6 +7,7 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; +import io.reactivex.annotations.NonNull; import org.shredzone.flattr4j.model.Flattr; import java.io.File; @@ -80,62 +81,72 @@ public class DBWriter { * @param context A context that is used for opening a database connection. * @param mediaId ID of the FeedMedia object whose downloaded file should be deleted. */ - public static Future<?> deleteFeedMediaOfItem(final Context context, + public static Future<?> deleteFeedMediaOfItem(@NonNull final Context context, final long mediaId) { return dbExec.submit(() -> { final FeedMedia media = DBReader.getFeedMedia(mediaId); if (media != null) { - Log.i(TAG, String.format("Requested to delete FeedMedia [id=%d, title=%s, downloaded=%s", - media.getId(), media.getEpisodeTitle(), String.valueOf(media.isDownloaded()))); - if (media.isDownloaded()) { - // delete downloaded media file - File mediaFile = new File(media.getFile_url()); - if (mediaFile.exists() && !mediaFile.delete()) { - MessageEvent evt = new MessageEvent(context.getString(R.string.delete_failed)); - EventBus.getDefault().post(evt); - return; - } - media.setDownloaded(false); - media.setFile_url(null); - media.setHasEmbeddedPicture(false); - PodDBAdapter adapter = PodDBAdapter.getInstance(); - adapter.open(); - adapter.setMedia(media); - adapter.close(); - - // If media is currently being played, change playback - // type to 'stream' and shutdown playback service - SharedPreferences prefs = PreferenceManager - .getDefaultSharedPreferences(context); - if (PlaybackPreferences.getCurrentlyPlayingMedia() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA) { - if (media.getId() == PlaybackPreferences - .getCurrentlyPlayingFeedMediaId()) { - SharedPreferences.Editor editor = prefs.edit(); - editor.putBoolean( - PlaybackPreferences.PREF_CURRENT_EPISODE_IS_STREAM, - true); - editor.commit(); - } - if (PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == media.getId()) { - IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE); - } - } - // Gpodder: queue delete action for synchronization - if(GpodnetPreferences.loggedIn()) { - FeedItem item = media.getItem(); - GpodnetEpisodeAction action = new GpodnetEpisodeAction.Builder(item, GpodnetEpisodeAction.Action.DELETE) - .currentDeviceId() - .currentTimestamp() - .build(); - GpodnetPreferences.enqueueEpisodeAction(action); - } + boolean result = deleteFeedMediaSynchronous(context, media); + + if (result && UserPreferences.shouldDeleteRemoveFromQueue()) { + DBWriter.removeQueueItemSynchronous(context, media.getItem(), false); } - EventBus.getDefault().post(FeedItemEvent.deletedMedia(Collections.singletonList(media.getItem()))); - EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast(); } }); } + private static boolean deleteFeedMediaSynchronous(@NonNull Context context, @NonNull FeedMedia media) { + Log.i(TAG, String.format("Requested to delete FeedMedia [id=%d, title=%s, downloaded=%s", + media.getId(), media.getEpisodeTitle(), String.valueOf(media.isDownloaded()))); + if (media.isDownloaded()) { + // delete downloaded media file + File mediaFile = new File(media.getFile_url()); + if (mediaFile.exists() && !mediaFile.delete()) { + MessageEvent evt = new MessageEvent(context.getString(R.string.delete_failed)); + EventBus.getDefault().post(evt); + return false; + } + media.setDownloaded(false); + media.setFile_url(null); + media.setHasEmbeddedPicture(false); + PodDBAdapter adapter = PodDBAdapter.getInstance(); + adapter.open(); + adapter.setMedia(media); + adapter.close(); + + // If media is currently being played, change playback + // type to 'stream' and shutdown playback service + SharedPreferences prefs = PreferenceManager + .getDefaultSharedPreferences(context); + if (PlaybackPreferences.getCurrentlyPlayingMedia() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA) { + if (media.getId() == PlaybackPreferences + .getCurrentlyPlayingFeedMediaId()) { + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean( + PlaybackPreferences.PREF_CURRENT_EPISODE_IS_STREAM, + true); + editor.commit(); + } + if (PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == media.getId()) { + IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE); + } + } + // Gpodder: queue delete action for synchronization + if(GpodnetPreferences.loggedIn()) { + FeedItem item = media.getItem(); + GpodnetEpisodeAction action = new GpodnetEpisodeAction.Builder(item, GpodnetEpisodeAction.Action.DELETE) + .currentDeviceId() + .currentTimestamp() + .build(); + GpodnetPreferences.enqueueEpisodeAction(action); + } + } + EventBus.getDefault().post(FeedItemEvent.deletedMedia(Collections.singletonList(media.getItem()))); + EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast(); + + return true; + } + /** * Deletes a Feed and all downloaded files of its components like images and downloaded episodes. * @@ -419,31 +430,33 @@ public class DBWriter { */ public static Future<?> removeQueueItem(final Context context, final FeedItem item, final boolean performAutoDownload) { - return dbExec.submit(() -> { - final PodDBAdapter adapter = PodDBAdapter.getInstance(); - adapter.open(); - final List<FeedItem> queue = DBReader.getQueue(adapter); + return dbExec.submit(() -> removeQueueItemSynchronous(context, item, performAutoDownload)); + } - if (queue != null) { - int position = queue.indexOf(item); - if (position >= 0) { - queue.remove(position); - adapter.setQueue(queue); - item.removeTag(FeedItem.TAG_QUEUE); - EventBus.getDefault().post(QueueEvent.removed(item)); - EventBus.getDefault().post(FeedItemEvent.updated(item)); - } else { - Log.w(TAG, "Queue was not modified by call to removeQueueItem"); - } + private static void removeQueueItemSynchronous(final Context context, + final FeedItem item, final boolean performAutoDownload) { + final PodDBAdapter adapter = PodDBAdapter.getInstance(); + adapter.open(); + final List<FeedItem> queue = DBReader.getQueue(adapter); + + if (queue != null) { + int position = queue.indexOf(item); + if (position >= 0) { + queue.remove(position); + adapter.setQueue(queue); + item.removeTag(FeedItem.TAG_QUEUE); + EventBus.getDefault().post(QueueEvent.removed(item)); + EventBus.getDefault().post(FeedItemEvent.updated(item)); } else { - Log.e(TAG, "removeQueueItem: Could not load queue"); - } - adapter.close(); - if (performAutoDownload) { - DBTasks.autodownloadUndownloadedItems(context); + Log.w(TAG, "Queue was not modified by call to removeQueueItem"); } - }); - + } else { + Log.e(TAG, "removeQueueItem: Could not load queue"); + } + adapter.close(); + if (performAutoDownload) { + DBTasks.autodownloadUndownloadedItems(context); + } } public static Future<?> addFavoriteItem(final FeedItem item) { 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 4566df2fc..f1410b894 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 @@ -1,5 +1,6 @@ package de.danoeh.antennapod.core.storage; +import android.annotation.SuppressLint; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; @@ -12,6 +13,7 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; import android.media.MediaMetadataRetriever; +import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; @@ -326,10 +328,14 @@ public class PodDBAdapter { return this; } + @SuppressLint("NewApi") private SQLiteDatabase openDb() { SQLiteDatabase newDb; try { newDb = SingletonHolder.dbHelper.getWritableDatabase(); + if (Build.VERSION.SDK_INT >= 16) { + newDb.disableWriteAheadLogging(); + } } catch (SQLException ex) { Log.e(TAG, Log.getStackTraceString(ex)); newDb = SingletonHolder.dbHelper.getReadableDatabase(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java b/core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java index 40faa1dd2..ffc6a6e28 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java @@ -1,6 +1,7 @@ package de.danoeh.antennapod.core.util; import android.net.Uri; +import android.support.annotation.NonNull; import android.util.Log; import de.danoeh.antennapod.core.BuildConfig; @@ -29,7 +30,7 @@ public final class URLChecker { * @param url The url which is going to be prepared * @return The prepared url */ - public static String prepareURL(String url) { + public static String prepareURL(@NonNull String url) { url = url.trim(); if (url.startsWith("feed://")) { if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://"); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java index 16d05dbb9..2b3f38841 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java @@ -35,6 +35,14 @@ public class AudioPlayer extends MediaPlayer implements IPlayer { } @Override + public void setPlaybackParams(float speed, boolean skipSilence) { + if(canSetSpeed()) { + setPlaybackSpeed(speed); + } + //Default player does not support silence skipping + } + + @Override protected boolean useSonic() { return UserPreferences.useSonic(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/IPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/IPlayer.java index a372f4241..c2b768ea8 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/IPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/IPlayer.java @@ -37,7 +37,7 @@ public interface IPlayer { void setDisplay(SurfaceHolder sh); - void setPlaybackSpeed(float f); + void setPlaybackParams(float speed, boolean skipSilence); void setDownmix(boolean enable); 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 847c5223b..01d6812fd 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 @@ -706,6 +706,11 @@ public abstract class PlaybackController { playbackService.setSpeed(speed); } } + public void setSkipSilence(boolean skipSilence) { + if (playbackService != null) { + playbackService.skipSilence(skipSilence); + } + } public void setVolume(float leftVolume, float rightVolume) { if (playbackService != null) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/VideoPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/VideoPlayer.java index 1d04fb878..f3c1c4f59 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/VideoPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/VideoPlayer.java @@ -22,9 +22,8 @@ public class VideoPlayer extends MediaPlayer implements IPlayer { } @Override - public void setPlaybackSpeed(float f) { - Log.e(TAG, "Setting playback speed unsupported in video player"); - throw new UnsupportedOperationException("Setting playback speed unsupported in video player"); + public void setPlaybackParams(float speed, boolean skipSilence) { + //Ignore this for non ExoPlayer implementations } @Override |