Search in sources :

Example 86 with FeedMedia

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

the class PlaybackVolumeUpdaterTest method updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsInitializing.

@Test
public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsInitializing() {
    PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
    when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.INITIALIZING);
    FeedMedia feedMedia = mockFeedMedia();
    when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
    FeedPreferences feedPreferences = feedMedia.getItem().getFeed().getPreferences();
    playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION);
    verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION);
    verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
    verify(mediaPlayer, never()).resume();
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Test(org.junit.Test)

Example 87 with FeedMedia

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

the class PlaybackVolumeUpdaterTest method noChangeIfPlayerStatusIsStopped.

@Test
public void noChangeIfPlayerStatusIsStopped() {
    PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
    when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.STOPPED);
    FeedMedia feedMedia = mockFeedMedia();
    when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
    playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF);
    verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
    verify(mediaPlayer, never()).resume();
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Test(org.junit.Test)

Example 88 with FeedMedia

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

the class PlayableUtils method saveCurrentPosition.

/**
 * Saves the current position of this object.
 *
 * @param newPosition  new playback position in ms
 * @param timestamp  current time in ms
 */
public static void saveCurrentPosition(Playable playable, int newPosition, long timestamp) {
    playable.setPosition(newPosition);
    playable.setLastPlayedTime(timestamp);
    if (playable instanceof FeedMedia) {
        FeedMedia media = (FeedMedia) playable;
        FeedItem item = media.getItem();
        if (item != null && item.isNew()) {
            DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
        }
        if (media.getStartPosition() >= 0 && playable.getPosition() > media.getStartPosition()) {
            media.setPlayedDuration(media.getPlayedDurationWhenStarted() + playable.getPosition() - media.getStartPosition());
        }
        DBWriter.setFeedMediaPlaybackInformation(media);
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia)

Example 89 with FeedMedia

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

the class FeedFilterTest method testMinimalDurationFilter.

@Test
public void testMinimalDurationFilter() {
    FeedItem download = new FeedItem();
    download.setTitle("Hello friend!");
    FeedMedia downloadMedia = FeedMediaMother.anyFeedMedia();
    downloadMedia.setDuration(Converter.durationStringShortToMs("05:00", false));
    download.setMedia(downloadMedia);
    // because duration of the media in unknown
    FeedItem download2 = new FeedItem();
    download2.setTitle("Hello friend!");
    FeedMedia unknownDurationMedia = FeedMediaMother.anyFeedMedia();
    download2.setMedia(unknownDurationMedia);
    // because it is not long enough
    FeedItem doNotDownload = new FeedItem();
    doNotDownload.setTitle("Hello friend!");
    FeedMedia doNotDownloadMedia = FeedMediaMother.anyFeedMedia();
    doNotDownloadMedia.setDuration(Converter.durationStringShortToMs("02:00", false));
    doNotDownload.setMedia(doNotDownloadMedia);
    int minimalDurationFilter = 3 * 60;
    FeedFilter filter = new FeedFilter("", "", minimalDurationFilter);
    assertTrue(filter.hasMinimalDurationFilter());
    assertTrue(filter.shouldAutoDownload(download));
    assertFalse(filter.shouldAutoDownload(doNotDownload));
    assertTrue(filter.shouldAutoDownload(download2));
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) FeedFilter(de.danoeh.antennapod.model.feed.FeedFilter) Test(org.junit.Test)

Example 90 with FeedMedia

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

the class Rss20 method handleElementStart.

@Override
public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) {
    if (ITEM.equals(localName) && CHANNEL.equals(state.getTagstack().lastElement().getName())) {
        state.setCurrentItem(new FeedItem());
        state.getItems().add(state.getCurrentItem());
        state.getCurrentItem().setFeed(state.getFeed());
    } else if (ENCLOSURE.equals(localName) && ITEM.equals(state.getTagstack().peek().getName())) {
        String type = attributes.getValue(ENC_TYPE);
        String url = attributes.getValue(ENC_URL);
        boolean validType = SyndTypeUtils.enclosureTypeValid(type);
        if (!validType) {
            type = SyndTypeUtils.getMimeTypeFromUrl(url);
            validType = SyndTypeUtils.enclosureTypeValid(type);
        }
        boolean validUrl = !TextUtils.isEmpty(url);
        if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null && validType && validUrl) {
            long size = 0;
            try {
                size = Long.parseLong(attributes.getValue(ENC_LEN));
                if (size < 16384) {
                    // less than 16kb is suspicious, check manually
                    size = 0;
                }
            } catch (NumberFormatException e) {
                Log.d(TAG, "Length attribute could not be parsed.");
            }
            FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
            state.getCurrentItem().setMedia(media);
        }
    }
    return new SyndElement(localName, this);
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) SyndElement(de.danoeh.antennapod.parser.feed.element.SyndElement)

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