Search in sources :

Example 51 with FeedMedia

use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method writeTestPlayable.

private Playable writeTestPlayable(String downloadUrl, String fileUrl) {
    Feed f = new Feed(0, null, "f", "l", "d", null, null, null, null, "i", null, null, "l", false);
    FeedPreferences prefs = new FeedPreferences(f.getId(), false, FeedPreferences.AutoDeleteAction.NO, VolumeAdaptionSetting.OFF, null, null);
    f.setPreferences(prefs);
    f.setItems(new ArrayList<>());
    FeedItem i = new FeedItem(0, "t", "i", "l", new Date(), FeedItem.UNPLAYED, f);
    f.getItems().add(i);
    FeedMedia media = new FeedMedia(0, i, 0, 0, 0, "audio/wav", fileUrl, downloadUrl, fileUrl != null, null, 0, 0);
    i.setMedia(media);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(f);
    assertTrue(media.getId() != 0);
    adapter.close();
    return media;
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 52 with FeedMedia

use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.

the class PlaybackTest method startLocalPlayback.

protected void startLocalPlayback() {
    openNavDrawer();
    onDrawerItem(withText(R.string.episodes_label)).perform(click());
    onView(isRoot()).perform(waitForView(withText(R.string.all_episodes_short_label), 1000));
    onView(withText(R.string.all_episodes_short_label)).perform(click());
    final List<FeedItem> episodes = DBReader.getRecentlyPublishedEpisodes(0, 10, FeedItemFilter.unfiltered());
    Matcher<View> allEpisodesMatcher = allOf(withId(android.R.id.list), isDisplayed(), hasMinimumChildCount(2));
    onView(isRoot()).perform(waitForView(allEpisodesMatcher, 1000));
    onView(allEpisodesMatcher).perform(actionOnItemAtPosition(0, clickChildViewWithId(R.id.secondaryActionButton)));
    FeedMedia media = episodes.get(0).getMedia();
    Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> media.getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId());
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) View(android.view.View) Espresso.onView(androidx.test.espresso.Espresso.onView) EspressoTestUtils.waitForView(de.test.antennapod.EspressoTestUtils.waitForView)

Example 53 with FeedMedia

use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.

the class AutoDownloadTest method playEpisode.

private void playEpisode(@NonNull FeedItem item) {
    FeedMedia media = item.getMedia();
    new PlaybackServiceStarter(context, media).callEvenIfRunning(true).startWhenPrepared(true).shouldStream(true).start();
    Awaitility.await("episode is playing").atMost(2000, MILLISECONDS).until(() -> item.getMedia().getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId());
}
Also used : PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia)

Example 54 with FeedMedia

use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.

the class DBReader method getFeedMedia.

/**
 * Searches the DB for a FeedMedia of the given id.
 *
 * @param mediaId The id of the object
 * @return The found object, or null if it does not exist
 */
@Nullable
public static FeedMedia getFeedMedia(final long mediaId) {
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    try (Cursor mediaCursor = adapter.getSingleFeedMediaCursor(mediaId)) {
        if (!mediaCursor.moveToFirst()) {
            return null;
        }
        int indexFeedItem = mediaCursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM);
        long itemId = mediaCursor.getLong(indexFeedItem);
        FeedMedia media = FeedMediaCursorMapper.convert(mediaCursor);
        FeedItem item = getFeedItem(itemId);
        if (item != null) {
            media.setItem(item);
            item.setMedia(media);
        }
        return media;
    } finally {
        adapter.close();
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Cursor(android.database.Cursor) Nullable(androidx.annotation.Nullable)

Example 55 with FeedMedia

use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.

the class DBReader method getStatistics.

/**
 * Searches the DB for statistics.
 *
 * @return The list of statistics objects
 */
@NonNull
public static List<StatisticsItem> getStatistics() {
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    List<StatisticsItem> feedTime = new ArrayList<>();
    List<Feed> feeds = getFeedList();
    for (Feed feed : feeds) {
        long feedPlayedTimeCountAll = 0;
        long feedPlayedTime = 0;
        long feedTotalTime = 0;
        long episodes = 0;
        long episodesStarted = 0;
        long episodesStartedIncludingMarked = 0;
        long totalDownloadSize = 0;
        long episodesDownloadCount = 0;
        List<FeedItem> items = getFeed(feed.getId()).getItems();
        for (FeedItem item : items) {
            FeedMedia media = item.getMedia();
            if (media == null) {
                continue;
            }
            feedPlayedTime += media.getPlayedDuration() / 1000;
            if (item.isPlayed()) {
                feedPlayedTimeCountAll += media.getDuration() / 1000;
            } else {
                feedPlayedTimeCountAll += media.getPosition() / 1000;
            }
            if (media.getPlaybackCompletionDate() != null || media.getPlayedDuration() > 0) {
                episodesStarted++;
            }
            if (item.isPlayed() || media.getPosition() != 0) {
                episodesStartedIncludingMarked++;
            }
            feedTotalTime += media.getDuration() / 1000;
            if (media.isDownloaded()) {
                totalDownloadSize += new File(media.getFile_url()).length();
                episodesDownloadCount++;
            }
            episodes++;
        }
        feedTime.add(new StatisticsItem(feed, feedTotalTime, feedPlayedTime, feedPlayedTimeCountAll, episodes, episodesStarted, episodesStartedIncludingMarked, totalDownloadSize, episodesDownloadCount));
    }
    adapter.close();
    return feedTime;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ArrayList(java.util.ArrayList) File(java.io.File) Feed(de.danoeh.antennapod.model.feed.Feed) NonNull(androidx.annotation.NonNull)

Aggregations

FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)91 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)46 Test (org.junit.Test)28 Feed (de.danoeh.antennapod.model.feed.Feed)26 Date (java.util.Date)25 ArrayList (java.util.ArrayList)18 FeedPreferences (de.danoeh.antennapod.model.feed.FeedPreferences)15 File (java.io.File)15 Playable (de.danoeh.antennapod.model.playback.Playable)8 View (android.view.View)6 NonNull (androidx.annotation.NonNull)6 Context (android.content.Context)5 Log (android.util.Log)5 PlaybackServiceStarter (de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter)5 Cursor (android.database.Cursor)4 Nullable (androidx.annotation.Nullable)4 R (de.danoeh.antennapod.R)4 DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)4 DownloadService (de.danoeh.antennapod.core.service.download.DownloadService)4 Intent (android.content.Intent)3