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