Search in sources :

Example 6 with FeedPreferences

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

the class PlaybackService method skipEndingIfNecessary.

private void skipEndingIfNecessary() {
    Playable playable = mediaPlayer.getPlayable();
    if (!(playable instanceof FeedMedia)) {
        return;
    }
    int duration = getDuration();
    int remainingTime = duration - getCurrentPosition();
    FeedMedia feedMedia = (FeedMedia) playable;
    FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
    int skipEnd = preferences.getFeedSkipEnding();
    if (skipEnd > 0 && skipEnd * 1000 < getDuration() && (remainingTime - (skipEnd * 1000) > 0) && ((remainingTime - skipEnd * 1000) < (getCurrentPlaybackSpeed() * 1000))) {
        Log.d(TAG, "skipEndingIfNecessary: Skipping the remaining " + remainingTime + " " + skipEnd * 1000 + " speed " + getCurrentPlaybackSpeed());
        Context context = getApplicationContext();
        String skipMesg = context.getString(R.string.pref_feed_skip_ending_toast, skipEnd);
        Toast toast = Toast.makeText(context, skipMesg, Toast.LENGTH_LONG);
        toast.show();
        this.autoSkippedFeedMediaId = feedMedia.getItem().getIdentifyingValue();
        mediaPlayer.skip();
    }
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) Context(android.content.Context) Toast(android.widget.Toast) Playable(de.danoeh.antennapod.model.playback.Playable) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia)

Example 7 with FeedPreferences

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

the class PlaybackVolumeUpdater method updateFeedMediaVolumeIfNecessary.

private void updateFeedMediaVolumeIfNecessary(PlaybackServiceMediaPlayer mediaPlayer, long feedId, VolumeAdaptionSetting volumeAdaptionSetting, FeedMedia feedMedia) {
    if (feedMedia.getItem().getFeed().getId() == feedId) {
        FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
        preferences.setVolumeAdaptionSetting(volumeAdaptionSetting);
        if (mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING) {
            forceUpdateVolume(mediaPlayer);
        }
    }
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences)

Example 8 with FeedPreferences

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

the class PlaybackVolumeUpdaterTest method updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPaused.

@Test
public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPaused() {
    PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
    when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PAUSED);
    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 9 with FeedPreferences

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

the class PlaybackVolumeUpdaterTest method updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPreparing.

@Test
public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPreparing() {
    PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
    when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PREPARING);
    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 10 with FeedPreferences

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

the class PlaybackVolumeUpdaterTest method updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPrepared.

@Test
public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsPrepared() {
    PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
    when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PREPARED);
    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)

Aggregations

FeedPreferences (de.danoeh.antennapod.model.feed.FeedPreferences)27 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)14 Feed (de.danoeh.antennapod.model.feed.Feed)8 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 NonNull (androidx.annotation.NonNull)3 Playable (de.danoeh.antennapod.model.playback.Playable)3 Context (android.content.Context)2 Toast (android.widget.Toast)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 PreferenceListDialog (de.danoeh.antennapod.fragment.preferences.dialog.PreferenceListDialog)2 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)2 VolumeAdaptionSetting (de.danoeh.antennapod.model.feed.VolumeAdaptionSetting)2 File (java.io.File)2 IOException (java.io.IOException)2 UiModeManager (android.app.UiModeManager)1 Log (android.util.Log)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 PluralsRes (androidx.annotation.PluralsRes)1