Search in sources :

Example 66 with FeedMedia

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

the class PlaybackPreferences method writeMediaPlaying.

public static void writeMediaPlaying(Playable playable, PlayerStatus playerStatus, boolean stream) {
    Log.d(TAG, "Writing playback preferences");
    SharedPreferences.Editor editor = prefs.edit();
    if (playable == null) {
        writeNoMediaPlaying();
    } else {
        editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA_TYPE, playable.getPlayableType());
        editor.putBoolean(PREF_CURRENT_EPISODE_IS_STREAM, stream);
        editor.putBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, playable.getMediaType() == MediaType.VIDEO);
        if (playable instanceof FeedMedia) {
            FeedMedia feedMedia = (FeedMedia) playable;
            editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, feedMedia.getItem().getFeed().getId());
            editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, feedMedia.getId());
        } else {
            editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, NO_MEDIA_PLAYING);
            editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
        }
        playable.writeToPreferences(editor);
    }
    editor.putInt(PREF_CURRENT_PLAYER_STATUS, getCurrentPlayerStatusAsInt(playerStatus));
    editor.apply();
}
Also used : SharedPreferences(android.content.SharedPreferences) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia)

Example 67 with FeedMedia

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

the class EpisodeItemViewHolder method bind.

private void bind(FeedMedia media) {
    isVideo.setVisibility(media.getMediaType() == MediaType.VIDEO ? View.VISIBLE : View.GONE);
    duration.setVisibility(media.getDuration() > 0 ? View.VISIBLE : View.GONE);
    if (FeedItemUtil.isCurrentlyPlaying(media)) {
        itemView.setBackgroundColor(ThemeUtils.getColorFromAttr(activity, R.attr.currently_playing_background));
    } else {
        itemView.setBackgroundResource(ThemeUtils.getDrawableFromAttr(activity, R.attr.selectableItemBackground));
    }
    if (DownloadService.isDownloadingFile(media.getDownload_url())) {
        final DownloadRequest downloadRequest = DownloadService.findRequest(media.getDownload_url());
        float percent = 0.01f * downloadRequest.getProgressPercent();
        secondaryActionProgress.setPercentage(Math.max(percent, 0.01f), item);
    } else if (media.isDownloaded()) {
        // Do not animate 100% -> 0%
        secondaryActionProgress.setPercentage(1, item);
    } else {
        // Animate X% -> 0%
        secondaryActionProgress.setPercentage(0, item);
    }
    duration.setText(Converter.getDurationStringLong(media.getDuration()));
    duration.setContentDescription(activity.getString(R.string.chapter_duration, Converter.getDurationStringLocalized(activity, media.getDuration())));
    if (FeedItemUtil.isPlaying(item.getMedia()) || item.isInProgress()) {
        int progress = (int) (100.0 * media.getPosition() / media.getDuration());
        int remainingTime = Math.max(media.getDuration() - media.getPosition(), 0);
        progressBar.setProgress(progress);
        position.setText(Converter.getDurationStringLong(media.getPosition()));
        position.setContentDescription(activity.getString(R.string.position, Converter.getDurationStringLocalized(activity, media.getPosition())));
        progressBar.setVisibility(View.VISIBLE);
        position.setVisibility(View.VISIBLE);
        if (UserPreferences.shouldShowRemainingTime()) {
            duration.setText(((remainingTime > 0) ? "-" : "") + Converter.getDurationStringLong(remainingTime));
            duration.setContentDescription(activity.getString(R.string.chapter_duration, Converter.getDurationStringLocalized(activity, (media.getDuration() - media.getPosition()))));
        }
    } else {
        progressBar.setVisibility(View.GONE);
        position.setVisibility(View.GONE);
    }
    if (media.getSize() > 0) {
        size.setText(Formatter.formatShortFileSize(activity, media.getSize()));
    } else if (NetworkUtils.isEpisodeHeadDownloadAllowed() && !media.checkedOnSizeButUnknown()) {
        size.setText("{fa-spinner}");
        Iconify.addIcons(size);
        NetworkUtils.getFeedMediaSizeObservable(media).subscribe(sizeValue -> {
            if (sizeValue > 0) {
                size.setText(Formatter.formatShortFileSize(activity, sizeValue));
            } else {
                size.setText("");
            }
        }, error -> {
            size.setText("");
            Log.e(TAG, Log.getStackTraceString(error));
        });
    } else {
        size.setText("");
    }
}
Also used : Converter(de.danoeh.antennapod.core.util.Converter) ProgressBar(android.widget.ProgressBar) ImageView(android.widget.ImageView) ItemActionButton(de.danoeh.antennapod.adapter.actionbutton.ItemActionButton) FeedItemUtil(de.danoeh.antennapod.core.util.FeedItemUtil) CoverLoader(de.danoeh.antennapod.adapter.CoverLoader) DateFormatter(de.danoeh.antennapod.core.util.DateFormatter) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) ImageResourceUtils(de.danoeh.antennapod.core.feed.util.ImageResourceUtils) NetworkUtils(de.danoeh.antennapod.core.util.NetworkUtils) CheckBox(android.widget.CheckBox) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) PlaybackPositionEvent(de.danoeh.antennapod.event.playback.PlaybackPositionEvent) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Build(android.os.Build) Log(android.util.Log) Formatter(android.text.format.Formatter) CardView(androidx.cardview.widget.CardView) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) PlaybackService(de.danoeh.antennapod.core.service.playback.PlaybackService) MediaType(de.danoeh.antennapod.model.playback.MediaType) ThemeUtils(de.danoeh.antennapod.ui.common.ThemeUtils) CircularProgressBar(de.danoeh.antennapod.ui.common.CircularProgressBar) LayoutInflater(android.view.LayoutInflater) R(de.danoeh.antennapod.R) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ViewGroup(android.view.ViewGroup) MainActivity(de.danoeh.antennapod.activity.MainActivity) TextView(android.widget.TextView) Layout(android.text.Layout) Iconify(com.joanzapata.iconify.Iconify) DownloadService(de.danoeh.antennapod.core.service.download.DownloadService) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest)

Example 68 with FeedMedia

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

the class DownloadLogAdapter method bind.

private void bind(DownloadLogItemViewHolder holder, DownloadStatus status, int position) {
    String statusText = "";
    if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
        statusText += context.getString(R.string.download_type_feed);
    } else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
        statusText += context.getString(R.string.download_type_media);
    }
    statusText += " ยท ";
    statusText += DateUtils.getRelativeTimeSpanString(status.getCompletionDate().getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0);
    holder.status.setText(statusText);
    if (status.getTitle() != null) {
        holder.title.setText(status.getTitle());
    } else {
        holder.title.setText(R.string.download_log_title_unknown);
    }
    if (status.isSuccessful()) {
        holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_success_green));
        holder.icon.setText("{fa-check-circle}");
        holder.icon.setContentDescription(context.getString(R.string.download_successful));
        holder.secondaryActionButton.setVisibility(View.INVISIBLE);
        holder.reason.setVisibility(View.GONE);
        holder.tapForDetails.setVisibility(View.GONE);
    } else {
        if (status.getReason() == DownloadError.ERROR_PARSER_EXCEPTION_DUPLICATE) {
            holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_warning_yellow));
            holder.icon.setText("{fa-exclamation-circle}");
        } else {
            holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_failed_red));
            holder.icon.setText("{fa-times-circle}");
        }
        holder.icon.setContentDescription(context.getString(R.string.error_label));
        holder.reason.setText(status.getReason().getErrorString(context));
        holder.reason.setVisibility(View.VISIBLE);
        holder.tapForDetails.setVisibility(View.VISIBLE);
        if (newerWasSuccessful(position - runningDownloads.size(), status.getFeedfileType(), status.getFeedfileId())) {
            holder.secondaryActionButton.setVisibility(View.INVISIBLE);
            holder.secondaryActionButton.setOnClickListener(null);
            holder.secondaryActionButton.setTag(null);
        } else {
            holder.secondaryActionIcon.setImageResource(R.drawable.ic_refresh);
            holder.secondaryActionButton.setVisibility(View.VISIBLE);
            if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
                holder.secondaryActionButton.setOnClickListener(v -> {
                    holder.secondaryActionButton.setVisibility(View.INVISIBLE);
                    Feed feed = DBReader.getFeed(status.getFeedfileId());
                    if (feed == null) {
                        Log.e(TAG, "Could not find feed for feed id: " + status.getFeedfileId());
                        return;
                    }
                    DBTasks.forceRefreshFeed(context, feed, true);
                });
            } else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
                holder.secondaryActionButton.setOnClickListener(v -> {
                    holder.secondaryActionButton.setVisibility(View.INVISIBLE);
                    FeedMedia media = DBReader.getFeedMedia(status.getFeedfileId());
                    if (media == null) {
                        Log.e(TAG, "Could not find feed media for feed id: " + status.getFeedfileId());
                        return;
                    }
                    DownloadService.download(context, true, DownloadRequestCreator.create(media).build());
                    ((MainActivity) context).showSnackbarAbovePlayer(R.string.status_downloading_label, Toast.LENGTH_SHORT);
                });
            }
        }
    }
}
Also used : DateUtils(android.text.format.DateUtils) DownloadRequestCreator(de.danoeh.antennapod.core.service.download.DownloadRequestCreator) ArrayList(java.util.ArrayList) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) Toast(android.widget.Toast) View(android.view.View) DownloadLogItemViewHolder(de.danoeh.antennapod.view.viewholder.DownloadLogItemViewHolder) ContextCompat(androidx.core.content.ContextCompat) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Log(android.util.Log) Feed(de.danoeh.antennapod.model.feed.Feed) Formatter(android.text.format.Formatter) Downloader(de.danoeh.antennapod.core.service.download.Downloader) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ThemeUtils(de.danoeh.antennapod.ui.common.ThemeUtils) R(de.danoeh.antennapod.R) DownloadError(de.danoeh.antennapod.core.util.DownloadError) ViewGroup(android.view.ViewGroup) MainActivity(de.danoeh.antennapod.activity.MainActivity) List(java.util.List) BaseAdapter(android.widget.BaseAdapter) DBReader(de.danoeh.antennapod.core.storage.DBReader) ListFragment(androidx.fragment.app.ListFragment) Activity(android.app.Activity) DownloadService(de.danoeh.antennapod.core.service.download.DownloadService) DBTasks(de.danoeh.antennapod.core.storage.DBTasks) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 69 with FeedMedia

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

the class ItemActionButton method forItem.

@NonNull
public static ItemActionButton forItem(@NonNull FeedItem item) {
    final FeedMedia media = item.getMedia();
    if (media == null) {
        return new MarkAsPlayedActionButton(item);
    }
    final boolean isDownloadingMedia = DownloadService.isDownloadingFile(media.getDownload_url());
    if (FeedItemUtil.isCurrentlyPlaying(media)) {
        return new PauseActionButton(item);
    } else if (item.getFeed().isLocalFeed()) {
        return new PlayLocalActionButton(item);
    } else if (media.isDownloaded()) {
        return new PlayActionButton(item);
    } else if (isDownloadingMedia) {
        return new CancelDownloadActionButton(item);
    } else if (UserPreferences.isStreamOverDownload()) {
        return new StreamActionButton(item);
    } else {
        return new DownloadActionButton(item);
    }
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) NonNull(androidx.annotation.NonNull)

Example 70 with FeedMedia

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

the class PlayActionButton method onClick.

@Override
public void onClick(Context context) {
    FeedMedia media = item.getMedia();
    if (media == null) {
        return;
    }
    if (!media.fileExists()) {
        DBTasks.notifyMissingFeedMediaFile(context, media);
        return;
    }
    new PlaybackServiceStarter(context, media).callEvenIfRunning(true).startWhenPrepared(true).shouldStream(false).start();
    if (media.getMediaType() == MediaType.VIDEO) {
        context.startActivity(PlaybackService.getPlayerActivityIntent(context, media));
    }
}
Also used : PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter) 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