use of de.danoeh.antennapod.model.feed.FeedPreferences in project AntennaPod by AntennaPod.
the class LocalPSMP method playMediaObject.
/**
* Internal implementation of playMediaObject. This method has an additional parameter that allows the caller to force a media player reset even if
* the given playable parameter is the same object as the currently playing media.
* <p/>
* This method requires the playerLock and is executed on the caller's thread.
*
* @see #playMediaObject(Playable, boolean, boolean, boolean)
*/
private void playMediaObject(@NonNull final Playable playable, final boolean forceReset, final boolean stream, final boolean startWhenPrepared, final boolean prepareImmediately) {
if (!playerLock.isHeldByCurrentThread()) {
throw new IllegalStateException("method requires playerLock");
}
if (media != null) {
if (!forceReset && media.getIdentifier().equals(playable.getIdentifier()) && playerStatus == PlayerStatus.PLAYING) {
// episode is already playing -> ignore method call
Log.d(TAG, "Method call to playMediaObject was ignored: media file already playing.");
return;
} else {
// stop playback of this episode
if (playerStatus == PlayerStatus.PAUSED || playerStatus == PlayerStatus.PLAYING || playerStatus == PlayerStatus.PREPARED) {
mediaPlayer.stop();
}
// set temporarily to pause in order to update list with current position
if (playerStatus == PlayerStatus.PLAYING) {
callback.onPlaybackPause(media, getPosition());
}
if (!media.getIdentifier().equals(playable.getIdentifier())) {
final Playable oldMedia = media;
executor.submit(() -> callback.onPostPlayback(oldMedia, false, false, true));
}
setPlayerStatus(PlayerStatus.INDETERMINATE, null);
}
}
this.media = playable;
this.stream = stream;
this.mediaType = media.getMediaType();
this.videoSize = null;
createMediaPlayer();
LocalPSMP.this.startWhenPrepared.set(startWhenPrepared);
setPlayerStatus(PlayerStatus.INITIALIZING, media);
try {
callback.ensureMediaInfoLoaded(media);
callback.onMediaChanged(false);
setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence());
if (stream) {
if (playable instanceof FeedMedia) {
FeedMedia feedMedia = (FeedMedia) playable;
FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
mediaPlayer.setDataSource(media.getStreamUrl(), preferences.getUsername(), preferences.getPassword());
} else {
mediaPlayer.setDataSource(media.getStreamUrl());
}
} else if (media.getLocalMediaUrl() != null && new File(media.getLocalMediaUrl()).canRead()) {
mediaPlayer.setDataSource(media.getLocalMediaUrl());
} else {
throw new IOException("Unable to read local file " + media.getLocalMediaUrl());
}
UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_CAR) {
setPlayerStatus(PlayerStatus.INITIALIZED, media);
}
if (prepareImmediately) {
setPlayerStatus(PlayerStatus.PREPARING, media);
mediaPlayer.prepare();
onPrepared(startWhenPrepared);
}
} catch (IOException | IllegalStateException e) {
e.printStackTrace();
setPlayerStatus(PlayerStatus.ERROR, null);
EventBus.getDefault().postSticky(new PlayerErrorEvent(e.getLocalizedMessage()));
}
}
use of de.danoeh.antennapod.model.feed.FeedPreferences in project AntennaPod by AntennaPod.
the class SubscriptionsFilter method filter.
/**
* Run a list of feed items through the filter.
*/
public List<Feed> filter(List<Feed> items, LongIntMap feedCounters) {
if (properties.length == 0) {
return items;
}
List<Feed> result = new ArrayList<>();
for (Feed item : items) {
FeedPreferences itemPreferences = item.getPreferences();
// If the item does not meet a requirement, skip it.
if (showAutoDownloadEnabled && !itemPreferences.getAutoDownload()) {
continue;
} else if (showAutoDownloadDisabled && itemPreferences.getAutoDownload()) {
continue;
}
if (showUpdatedEnabled && !itemPreferences.getKeepUpdated()) {
continue;
} else if (showUpdatedDisabled && itemPreferences.getKeepUpdated()) {
continue;
}
if (showEpisodeNotificationEnabled && !itemPreferences.getShowEpisodeNotification()) {
continue;
} else if (showEpisodeNotificationDisabled && itemPreferences.getShowEpisodeNotification()) {
continue;
}
// If the item reaches here, it meets all criteria (except counter > 0)
result.add(item);
}
if (showIfCounterGreaterZero) {
for (int i = result.size() - 1; i >= 0; i--) {
if (feedCounters.get(result.get(i).getId()) <= 0) {
result.remove(i);
}
}
}
return result;
}
use of de.danoeh.antennapod.model.feed.FeedPreferences in project AntennaPod by AntennaPod.
the class FeedMultiSelectActionHandler method autoDownloadPrefHandler.
private void autoDownloadPrefHandler() {
PreferenceSwitchDialog preferenceSwitchDialog = new PreferenceSwitchDialog(activity, activity.getString(R.string.auto_download_settings_label), activity.getString(R.string.auto_download_label));
preferenceSwitchDialog.setOnPreferenceChangedListener(new PreferenceSwitchDialog.OnPreferenceChangedListener() {
@Override
public void preferenceChanged(boolean enabled) {
saveFeedPreferences(feedPreferences -> feedPreferences.setAutoDownload(enabled));
}
});
preferenceSwitchDialog.openDialog();
}
use of de.danoeh.antennapod.model.feed.FeedPreferences in project AntennaPod by AntennaPod.
the class FeedMultiSelectActionHandler method editFeedPrefTags.
private void editFeedPrefTags() {
ArrayList<FeedPreferences> preferencesList = new ArrayList<>();
for (Feed feed : selectedItems) {
preferencesList.add(feed.getPreferences());
}
TagSettingsDialog.newInstance(preferencesList).show(activity.getSupportFragmentManager(), TagSettingsDialog.TAG);
}
use of de.danoeh.antennapod.model.feed.FeedPreferences in project AntennaPod by AntennaPod.
the class PlaybackVolumeUpdaterTest method updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsSeeking.
@Test
public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsSeeking() {
PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.SEEKING);
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();
}
Aggregations