added media to queue when playing (#4058)
This commit is contained in:
parent
c8790336b7
commit
3a86745e81
|
@ -5,9 +5,25 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.test.filters.LargeTest;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
|
@ -24,19 +40,6 @@ import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
|||
import de.test.antennapod.EspressoTestUtils;
|
||||
import de.test.antennapod.IgnoreOnCi;
|
||||
import de.test.antennapod.ui.UITestUtils;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
|
@ -54,6 +57,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
|||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -193,6 +197,18 @@ public class PlaybackTest {
|
|||
startLocalPlayback();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayingItemAddsToQueue() throws Exception {
|
||||
uiTestUtils.addLocalFeedData(true);
|
||||
activityTestRule.launchActivity(new Intent());
|
||||
DBWriter.clearQueue().get();
|
||||
List<FeedItem> queue = DBReader.getQueue();
|
||||
assertEquals(0, queue.size());
|
||||
startLocalPlayback();
|
||||
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(
|
||||
() -> 1 == DBReader.getQueue().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContinousPlaybackOffSingleEpisode() throws Exception {
|
||||
setContinuousPlaybackPreference(false);
|
||||
|
|
|
@ -497,6 +497,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
return Service.START_NOT_STICKY;
|
||||
}
|
||||
mediaPlayer.playMediaObject(playable, stream, startWhenPrepared, prepareImmediately);
|
||||
addPlayableToQueue(playable);
|
||||
} else {
|
||||
Log.d(TAG, "Did not handle intent to PlaybackService: " + intent);
|
||||
Log.d(TAG, "Extras: " + intent.getExtras());
|
||||
|
@ -652,6 +653,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
mediaPlayer.playMediaObject(playable, PlaybackPreferences.getCurrentEpisodeIsStream(), true, true);
|
||||
stateManager.validStartCommandWasReceived();
|
||||
PlaybackService.this.updateMediaSessionMetadata(playable);
|
||||
addPlayableToQueue(playable);
|
||||
} else {
|
||||
stateManager.stopService();
|
||||
}
|
||||
|
@ -1636,6 +1638,13 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
}
|
||||
}
|
||||
|
||||
private void addPlayableToQueue(Playable playable) {
|
||||
if (playable instanceof FeedMedia) {
|
||||
long itemId = ((FeedMedia) playable).getId();
|
||||
DBWriter.addQueueItem(this, false, false, itemId);
|
||||
}
|
||||
}
|
||||
|
||||
private final MediaSessionCompat.Callback sessionCallback = new MediaSessionCompat.Callback() {
|
||||
|
||||
private static final String TAG = "MediaSessionCompat";
|
||||
|
@ -1658,6 +1667,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
FeedMedia p = DBReader.getFeedMedia(Long.parseLong(mediaId));
|
||||
if (p != null) {
|
||||
mediaPlayer.playMediaObject(p, !p.localFileAvailable(), true, true);
|
||||
addPlayableToQueue(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1669,6 +1679,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
if (results.size() > 0 && results.get(0).getMedia() != null) {
|
||||
FeedMedia media = results.get(0).getMedia();
|
||||
mediaPlayer.playMediaObject(media, !media.localFileAvailable(), true, true);
|
||||
addPlayableToQueue(media);
|
||||
return;
|
||||
}
|
||||
onPlay();
|
||||
|
|
Loading…
Reference in New Issue