load Media info from DB in order to grab last saved position (#5624)

This commit is contained in:
Tony Tam 2022-01-06 03:01:50 -08:00 committed by GitHub
parent 4670a88e09
commit 38c470eace
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 13 deletions

View File

@ -72,7 +72,6 @@ import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.receiver.MediaButtonReceiver;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.FeedSearcher;
import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink;
@ -997,13 +996,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
return null;
}
FeedItem nextItem;
try {
final List<FeedItem> queue = taskManager.getQueue();
nextItem = DBTasks.getQueueSuccessorOfItem(item.getId(), queue);
} catch (InterruptedException e) {
Log.e(TAG, "Error handling the queue in order to retrieve the next item", e);
return null;
}
nextItem = DBReader.getNextInQueue(item);
if (nextItem == null || nextItem.getMedia() == null) {
PlaybackPreferences.writeNoMediaPlaying();
@ -1021,16 +1014,15 @@ public class PlaybackService extends MediaBrowserServiceCompat {
&& UserPreferences.isFollowQueue() && !nextItem.getFeed().isLocalFeed()) {
displayStreamingNotAllowedNotification(
new PlaybackServiceStarter(this, nextItem.getMedia())
.prepareImmediately(true)
.startWhenPrepared(true)
.shouldStream(true)
.getIntent());
.prepareImmediately(true)
.startWhenPrepared(true)
.shouldStream(true)
.getIntent());
PlaybackPreferences.writeNoMediaPlaying();
stateManager.stopService();
return null;
}
return nextItem.getMedia();
}
/**

View File

@ -564,6 +564,34 @@ public final class DBReader {
}
}
/**
* Get next feed item in queue following a particular feeditem
*
* @param item The FeedItem
* @return The FeedItem next in queue or null if the FeedItem could not be found.
*/
@Nullable
public static FeedItem getNextInQueue(FeedItem item) {
Log.d(TAG, "getNextInQueue() called with: " + "itemId = [" + item.getId() + "]");
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
try {
FeedItem nextItem = null;
try (Cursor cursor = adapter.getNextInQueue(item)) {
List<FeedItem> list = extractItemlistFromCursor(adapter, cursor);
if (!list.isEmpty()) {
nextItem = list.get(0);
loadAdditionalFeedItemListData(list);
}
return nextItem;
} catch (Exception e) {
return null;
}
} finally {
adapter.close();
}
}
/**
* Loads a specific FeedItem from the database.
*

View File

@ -982,6 +982,18 @@ public class PodDBAdapter {
return db.query(TABLE_NAME_QUEUE, new String[]{KEY_FEEDITEM}, null, null, null, null, KEY_ID + " ASC", null);
}
public Cursor getNextInQueue(final FeedItem item) {
final String query = SELECT_FEED_ITEMS_AND_MEDIA
+ "INNER JOIN " + TABLE_NAME_QUEUE
+ " ON " + SELECT_KEY_ITEM_ID + " = " + TABLE_NAME_QUEUE + "." + KEY_FEEDITEM
+ " WHERE Queue.ID > (SELECT Queue.ID FROM Queue WHERE Queue.FeedItem = "
+ item.getId()
+ ")"
+ " ORDER BY Queue.ID"
+ " LIMIT 1";
return db.rawQuery(query, null);
}
public final Cursor getFavoritesCursor(int offset, int limit) {
final String query = SELECT_FEED_ITEMS_AND_MEDIA
+ " INNER JOIN " + TABLE_NAME_FAVORITES