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();
}
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();
}
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);
}
}
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));
}
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);
}
Aggregations