diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-09-30 21:34:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-30 21:34:17 +0200 |
commit | f862d157531edb0db7ed7c89f69248b8deb0f907 (patch) | |
tree | 9d80d634941d650cb63f30a68caa12faa217f38e /core | |
parent | 694d0f8d349adabe984732a976ba2556b79d5555 (diff) | |
parent | c0befc98542bc147a8aa341c48e6445d4cfbbfb7 (diff) | |
download | AntennaPod-f862d157531edb0db7ed7c89f69248b8deb0f907.zip |
Merge pull request #3471 from orionlee/bugfix2_player_not_using_downloaded_media_2947
New fix player stuck due to streaming rather than using downloaded media
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java | 7 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java | 34 |
2 files changed, 37 insertions, 4 deletions
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 ce61bff68..4b6416384 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 @@ -997,14 +997,17 @@ public class DownloadService extends Service { final FeedItem item = media.getItem(); try { + DBWriter.setFeedMedia(media).get(); + // we've received the media, we don't want to autodownload it again if (item != null) { item.setAutoDownload(false); + // setFeedItem() signals (via EventBus) that the item has been updated, + // so we do it after the enclosing media has been updated above, + // to ensure subscribers will get the updated FeedMedia as well DBWriter.setFeedItem(item).get(); } - DBWriter.setFeedMedia(media).get(); - if (item != null && UserPreferences.enqueueDownloadedEpisodes() && !DBTasks.isInQueue(DownloadService.this, item.getId())) { DBWriter.addQueueItem(DownloadService.this, item).get(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java index 68839023e..1a13f9e9f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java @@ -7,6 +7,9 @@ import android.os.Vibrator; import android.support.annotation.NonNull; import android.util.Log; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; + import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -14,13 +17,12 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import de.danoeh.antennapod.core.event.FeedItemEvent; import de.danoeh.antennapod.core.event.QueueEvent; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.util.playback.Playable; -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; import io.reactivex.Completable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; @@ -102,6 +104,34 @@ public class PlaybackServiceTaskManager { } } + @Subscribe + public void onEvent(FeedItemEvent event) { + // Use case: when an item in the queue has been downloaded, + // listening to the event to ensure the downloaded item will be used. + Log.d(TAG, "onEvent(FeedItemEvent " + event + ")"); + + for (FeedItem item : event.items) { + if (isItemInQueue(item.getId())) { + Log.d(TAG, "onEvent(FeedItemEvent) - some item (" + item.getId() + ") in the queue has been updated (usually downloaded). Refresh the queue."); + cancelQueueLoader(); + loadQueue(); + return; + } + } + } + + private boolean isItemInQueue(long itemId) { + List<FeedItem> queue = getQueueIfLoaded(); + if (queue != null) { + for (FeedItem item : queue) { + if (item.getId() == itemId) { + return true; + } + } + } + return false; + } + /** * Returns the queue if it is already loaded or null if it hasn't been loaded yet. * In order to wait until the queue has been loaded, use getQueue() |