load Media info from DB in order to grab last saved position (#5624)
This commit is contained in:
parent
4670a88e09
commit
38c470eace
|
@ -72,7 +72,6 @@ import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.receiver.MediaButtonReceiver;
|
import de.danoeh.antennapod.core.receiver.MediaButtonReceiver;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
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.DBWriter;
|
||||||
import de.danoeh.antennapod.core.storage.FeedSearcher;
|
import de.danoeh.antennapod.core.storage.FeedSearcher;
|
||||||
import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink;
|
import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink;
|
||||||
|
@ -997,13 +996,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
FeedItem nextItem;
|
FeedItem nextItem;
|
||||||
try {
|
nextItem = DBReader.getNextInQueue(item);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nextItem == null || nextItem.getMedia() == null) {
|
if (nextItem == null || nextItem.getMedia() == null) {
|
||||||
PlaybackPreferences.writeNoMediaPlaying();
|
PlaybackPreferences.writeNoMediaPlaying();
|
||||||
|
@ -1021,16 +1014,15 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||||
&& UserPreferences.isFollowQueue() && !nextItem.getFeed().isLocalFeed()) {
|
&& UserPreferences.isFollowQueue() && !nextItem.getFeed().isLocalFeed()) {
|
||||||
displayStreamingNotAllowedNotification(
|
displayStreamingNotAllowedNotification(
|
||||||
new PlaybackServiceStarter(this, nextItem.getMedia())
|
new PlaybackServiceStarter(this, nextItem.getMedia())
|
||||||
.prepareImmediately(true)
|
.prepareImmediately(true)
|
||||||
.startWhenPrepared(true)
|
.startWhenPrepared(true)
|
||||||
.shouldStream(true)
|
.shouldStream(true)
|
||||||
.getIntent());
|
.getIntent());
|
||||||
PlaybackPreferences.writeNoMediaPlaying();
|
PlaybackPreferences.writeNoMediaPlaying();
|
||||||
stateManager.stopService();
|
stateManager.stopService();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return nextItem.getMedia();
|
return nextItem.getMedia();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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.
|
* Loads a specific FeedItem from the database.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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);
|
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) {
|
public final Cursor getFavoritesCursor(int offset, int limit) {
|
||||||
final String query = SELECT_FEED_ITEMS_AND_MEDIA
|
final String query = SELECT_FEED_ITEMS_AND_MEDIA
|
||||||
+ " INNER JOIN " + TABLE_NAME_FAVORITES
|
+ " INNER JOIN " + TABLE_NAME_FAVORITES
|
||||||
|
|
Loading…
Reference in New Issue