Search in sources :

Example 6 with FeedMedia

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

the class ImageResourceUtils method getFallbackImageLocation.

@Nullable
public static String getFallbackImageLocation(@NonNull Playable playable) {
    if (playable instanceof FeedMedia) {
        FeedMedia media = (FeedMedia) playable;
        FeedItem item = media.getItem();
        if (item != null && item.getFeed() != null) {
            return item.getFeed().getImageUrl();
        } else {
            return null;
        }
    } else {
        return playable.getImageLocation();
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Nullable(androidx.annotation.Nullable)

Example 7 with FeedMedia

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

the class LocalPSMP method setVolumeSync.

/**
 * Sets the playback volume.
 * This method is executed on the caller's thread.
 */
private void setVolumeSync(float volumeLeft, float volumeRight) {
    playerLock.lock();
    Playable playable = getPlayable();
    if (playable instanceof FeedMedia) {
        FeedMedia feedMedia = (FeedMedia) playable;
        FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
        VolumeAdaptionSetting volumeAdaptionSetting = preferences.getVolumeAdaptionSetting();
        float adaptionFactor = volumeAdaptionSetting.getAdaptionFactor();
        volumeLeft *= adaptionFactor;
        volumeRight *= adaptionFactor;
    }
    mediaPlayer.setVolume(volumeLeft, volumeRight);
    Log.d(TAG, "Media player volume was set to " + volumeLeft + " " + volumeRight);
    playerLock.unlock();
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) Playable(de.danoeh.antennapod.model.playback.Playable) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) VolumeAdaptionSetting(de.danoeh.antennapod.model.feed.VolumeAdaptionSetting)

Example 8 with FeedMedia

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

the class PlaybackService method skipIntroEndingPresetChanged.

@Subscribe(threadMode = ThreadMode.MAIN)
@SuppressWarnings("unused")
public void skipIntroEndingPresetChanged(SkipIntroEndingChangedEvent event) {
    if (getPlayable() instanceof FeedMedia) {
        if (((FeedMedia) getPlayable()).getItem().getFeed().getId() == event.getFeedId()) {
            if (event.getSkipEnding() != 0) {
                FeedPreferences feedPreferences = ((FeedMedia) getPlayable()).getItem().getFeed().getPreferences();
                feedPreferences.setFeedSkipIntro(event.getSkipIntro());
                feedPreferences.setFeedSkipEnding(event.getSkipEnding());
            }
        }
    }
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 9 with FeedMedia

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

the class PlaybackService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    Log.d(TAG, "OnStartCommand called");
    stateManager.startForeground(R.id.notification_playing, notificationBuilder.build());
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.cancel(R.id.notification_streaming_confirmation);
    final int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
    final boolean hardwareButton = intent.getBooleanExtra(MediaButtonReceiver.EXTRA_HARDWAREBUTTON, false);
    Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE);
    if (keycode == -1 && playable == null) {
        Log.e(TAG, "PlaybackService was started with no arguments");
        stateManager.stopService();
        return Service.START_NOT_STICKY;
    }
    if ((flags & Service.START_FLAG_REDELIVERY) != 0) {
        Log.d(TAG, "onStartCommand is a redelivered intent, calling stopForeground now.");
        stateManager.stopForeground(true);
    } else {
        if (keycode != -1) {
            boolean notificationButton;
            if (hardwareButton) {
                Log.d(TAG, "Received hardware button event");
                notificationButton = false;
            } else {
                Log.d(TAG, "Received media button event");
                notificationButton = true;
            }
            boolean handled = handleKeycode(keycode, notificationButton);
            if (!handled && !stateManager.hasReceivedValidStartCommand()) {
                stateManager.stopService();
                return Service.START_NOT_STICKY;
            }
        } else {
            stateManager.validStartCommandWasReceived();
            boolean stream = intent.getBooleanExtra(EXTRA_SHOULD_STREAM, true);
            boolean allowStreamThisTime = intent.getBooleanExtra(EXTRA_ALLOW_STREAM_THIS_TIME, false);
            boolean allowStreamAlways = intent.getBooleanExtra(EXTRA_ALLOW_STREAM_ALWAYS, false);
            boolean startWhenPrepared = intent.getBooleanExtra(EXTRA_START_WHEN_PREPARED, false);
            boolean prepareImmediately = intent.getBooleanExtra(EXTRA_PREPARE_IMMEDIATELY, false);
            sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
            if (allowStreamAlways) {
                UserPreferences.setAllowMobileStreaming(true);
            }
            boolean localFeed = URLUtil.isContentUrl(playable.getStreamUrl());
            if (stream && !NetworkUtils.isStreamingAllowed() && !allowStreamThisTime && !localFeed) {
                displayStreamingNotAllowedNotification(intent);
                PlaybackPreferences.writeNoMediaPlaying();
                stateManager.stopService();
                return Service.START_NOT_STICKY;
            }
            Observable.fromCallable(() -> {
                if (playable instanceof FeedMedia) {
                    return DBReader.getFeedMedia(((FeedMedia) playable).getId());
                } else {
                    return playable;
                }
            }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(playableLoaded -> {
                if (!playable.getIdentifier().equals(PlaybackPreferences.getCurrentlyPlayingFeedMediaId())) {
                    PlaybackPreferences.clearCurrentlyPlayingTemporaryPlaybackSpeed();
                }
                mediaPlayer.playMediaObject(playableLoaded, stream, startWhenPrepared, prepareImmediately);
                addPlayableToQueue(playableLoaded);
            }, error -> {
                Log.d(TAG, "Playable was not found. Stopping service.");
                error.printStackTrace();
                stateManager.stopService();
            });
            return Service.START_NOT_STICKY;
        }
    }
    return Service.START_NOT_STICKY;
}
Also used : Playable(de.danoeh.antennapod.model.playback.Playable) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat)

Example 10 with FeedMedia

use of de.danoeh.antennapod.model.feed.FeedMedia 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)

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