Search in sources :

Example 1 with RemoteMedia

use of de.danoeh.antennapod.model.playback.RemoteMedia in project AntennaPod by AntennaPod.

the class FeedItemlistDescriptionAdapter method getView.

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    Holder holder;
    FeedItem item = getItem(position);
    // Inflate layout
    if (convertView == null) {
        holder = new Holder();
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.itemdescription_listitem, parent, false);
        holder.title = convertView.findViewById(R.id.txtvTitle);
        holder.pubDate = convertView.findViewById(R.id.txtvPubDate);
        holder.description = convertView.findViewById(R.id.txtvDescription);
        holder.preview = convertView.findViewById(R.id.butPreview);
        convertView.setTag(holder);
    } else {
        holder = (Holder) convertView.getTag();
    }
    holder.title.setText(item.getTitle());
    holder.pubDate.setText(DateFormatter.formatAbbrev(getContext(), item.getPubDate()));
    if (item.getDescription() != null) {
        String description = HtmlToPlainText.getPlainText(item.getDescription()).replaceAll("\n", " ").replaceAll("\\s+", " ").trim();
        holder.description.setText(description);
        holder.description.setMaxLines(MAX_LINES_COLLAPSED);
    }
    // not expanded
    holder.description.setTag(Boolean.FALSE);
    holder.preview.setVisibility(View.GONE);
    holder.preview.setOnClickListener(v -> {
        if (item.getMedia() == null) {
            return;
        }
        Playable playable = new RemoteMedia(item);
        if (!NetworkUtils.isStreamingAllowed()) {
            new StreamingConfirmationDialog(getContext(), playable).show();
            return;
        }
        new PlaybackServiceStarter(getContext(), playable).shouldStream(true).startWhenPrepared(true).callEvenIfRunning(true).start();
        if (playable.getMediaType() == MediaType.VIDEO) {
            getContext().startActivity(PlaybackService.getPlayerActivityIntent(getContext(), playable));
        }
    });
    convertView.setOnClickListener(v -> {
        if (holder.description.getTag() == Boolean.TRUE) {
            holder.description.setMaxLines(MAX_LINES_COLLAPSED);
            holder.preview.setVisibility(View.GONE);
            holder.description.setTag(Boolean.FALSE);
        } else {
            holder.description.setMaxLines(30);
            holder.description.setTag(Boolean.TRUE);
            holder.preview.setVisibility(item.getMedia() != null ? View.VISIBLE : View.GONE);
            holder.preview.setText(R.string.preview_episode);
        }
    });
    return convertView;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter) Playable(de.danoeh.antennapod.model.playback.Playable) LayoutInflater(android.view.LayoutInflater) RemoteMedia(de.danoeh.antennapod.model.playback.RemoteMedia) StreamingConfirmationDialog(de.danoeh.antennapod.dialog.StreamingConfirmationDialog) NonNull(androidx.annotation.NonNull)

Example 2 with RemoteMedia

use of de.danoeh.antennapod.model.playback.RemoteMedia in project AntennaPod by AntennaPod.

the class CastUtils method makeRemoteMedia.

/**
 * Converts {@link MediaInfo} objects into the appropriate implementation of {@link Playable}.
 * @return {@link Playable} object in a format proper for casting.
 */
public static Playable makeRemoteMedia(MediaInfo media) {
    MediaMetadata metadata = media.getMetadata();
    int version = metadata.getInt(KEY_FORMAT_VERSION);
    if (version <= 0 || version > MAX_VERSION_FORWARD_COMPATIBILITY) {
        Log.w(TAG, "MediaInfo object obtained from the cast device is not compatible with this" + "version of AntennaPod CastUtils, curVer=" + FORMAT_VERSION_VALUE + ", object version=" + version);
        return null;
    }
    List<WebImage> imageList = metadata.getImages();
    String imageUrl = null;
    if (!imageList.isEmpty()) {
        imageUrl = imageList.get(0).getUrl().toString();
    }
    String notes = metadata.getString(KEY_EPISODE_NOTES);
    RemoteMedia result = new RemoteMedia(media.getContentId(), metadata.getString(KEY_EPISODE_IDENTIFIER), metadata.getString(KEY_FEED_URL), metadata.getString(MediaMetadata.KEY_SUBTITLE), metadata.getString(MediaMetadata.KEY_TITLE), metadata.getString(KEY_EPISODE_LINK), metadata.getString(MediaMetadata.KEY_ARTIST), imageUrl, metadata.getString(KEY_FEED_WEBSITE), media.getContentType(), metadata.getDate(MediaMetadata.KEY_RELEASE_DATE).getTime(), notes);
    if (result.getDuration() == 0 && media.getStreamDuration() > 0) {
        result.setDuration((int) media.getStreamDuration());
    }
    return result;
}
Also used : RemoteMedia(de.danoeh.antennapod.model.playback.RemoteMedia) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage)

Aggregations

RemoteMedia (de.danoeh.antennapod.model.playback.RemoteMedia)2 LayoutInflater (android.view.LayoutInflater)1 NonNull (androidx.annotation.NonNull)1 MediaMetadata (com.google.android.gms.cast.MediaMetadata)1 WebImage (com.google.android.gms.common.images.WebImage)1 PlaybackServiceStarter (de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter)1 StreamingConfirmationDialog (de.danoeh.antennapod.dialog.StreamingConfirmationDialog)1 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)1 Playable (de.danoeh.antennapod.model.playback.Playable)1