diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2020-03-16 00:58:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-16 00:58:12 +0100 |
commit | 6fd1f8e692026982656b2489777e4e9cb17940a7 (patch) | |
tree | c4c54d5b9be692fac7b33df3afb875dcf36cb402 /core | |
parent | 436187842756beee9b76dba898a172d2a73a7b5e (diff) | |
parent | f7411d2d98033ab8bce3be9c4428b18fe5201e74 (diff) | |
download | AntennaPod-6fd1f8e692026982656b2489777e4e9cb17940a7.zip |
Merge pull request #3882 from ByteHamster/stream-unsubscribed-episode
Allow to stream episodes from unsubscribed podcast
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/playback/RemoteMedia.java (renamed from core/src/play/java/de/danoeh/antennapod/core/cast/RemoteMedia.java) | 136 | ||||
-rw-r--r-- | core/src/main/res/values/strings.xml | 1 | ||||
-rw-r--r-- | core/src/play/java/de/danoeh/antennapod/core/cast/CastUtils.java | 1 | ||||
-rw-r--r-- | core/src/play/java/de/danoeh/antennapod/core/cast/MediaInfoCreator.java | 60 | ||||
-rw-r--r-- | core/src/play/java/de/danoeh/antennapod/core/feed/FeedMediaFlavorHelper.java | 2 | ||||
-rw-r--r-- | core/src/play/java/de/danoeh/antennapod/core/service/playback/RemotePSMP.java | 5 |
6 files changed, 128 insertions, 77 deletions
diff --git a/core/src/play/java/de/danoeh/antennapod/core/cast/RemoteMedia.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/RemoteMedia.java index 0614e5952..c39121564 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/cast/RemoteMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/RemoteMedia.java @@ -1,35 +1,26 @@ -package de.danoeh.antennapod.core.cast; +package de.danoeh.antennapod.core.util.playback; import android.content.Context; import android.content.SharedPreferences; -import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; -import androidx.annotation.Nullable; import android.text.TextUtils; - -import com.google.android.gms.cast.MediaInfo; -import com.google.android.gms.cast.MediaMetadata; -import com.google.android.gms.common.images.WebImage; - -import org.apache.commons.lang3.builder.HashCodeBuilder; - -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.concurrent.Callable; - +import androidx.annotation.Nullable; import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.util.ChapterUtils; -import de.danoeh.antennapod.core.util.playback.Playable; +import java.util.Date; +import java.util.List; +import java.util.concurrent.Callable; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** - * Playable implementation for media on a Cast Device for which a local version of + * Playable implementation for media for which a local version of * {@link de.danoeh.antennapod.core.feed.FeedMedia} hasn't been found. + * Used for Casting and for previewing unsubscribed feeds. */ public class RemoteMedia implements Playable { public static final String TAG = "RemoteMedia"; @@ -45,7 +36,7 @@ public class RemoteMedia implements Playable { private String feedAuthor; private String imageUrl; private String feedLink; - private String mime_type; + private String mimeType; private Date pubDate; private String notes; private List<Chapter> chapters; @@ -55,7 +46,7 @@ public class RemoteMedia implements Playable { public RemoteMedia(String downloadUrl, String itemId, String feedUrl, String feedTitle, String episodeTitle, String episodeLink, String feedAuthor, - String imageUrl, String feedLink, String mime_type, Date pubDate) { + String imageUrl, String feedLink, String mimeType, Date pubDate) { this.downloadUrl = downloadUrl; this.itemIdentifier = itemId; this.feedUrl = feedUrl; @@ -65,61 +56,26 @@ public class RemoteMedia implements Playable { this.feedAuthor = feedAuthor; this.imageUrl = imageUrl; this.feedLink = feedLink; - this.mime_type = mime_type; + this.mimeType = mimeType; this.pubDate = pubDate; } - public void setNotes(String notes) { - this.notes = notes; + public RemoteMedia(FeedItem item) { + this.downloadUrl = item.getMedia().getDownload_url(); + this.itemIdentifier = item.getItemIdentifier(); + this.feedUrl = item.getFeed().getDownload_url(); + this.feedTitle = item.getFeed().getTitle(); + this.episodeTitle = item.getTitle(); + this.episodeLink = item.getLink(); + this.feedAuthor = item.getFeed().getAuthor(); + this.imageUrl = item.getImageUrl(); + this.feedLink = item.getFeed().getLink(); + this.mimeType = item.getMedia().getMime_type(); + this.pubDate = item.getPubDate(); } - public MediaInfo extractMediaInfo() { - MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC); - - metadata.putString(MediaMetadata.KEY_TITLE, episodeTitle); - metadata.putString(MediaMetadata.KEY_SUBTITLE, feedTitle); - if (!TextUtils.isEmpty(imageUrl)) { - metadata.addImage(new WebImage(Uri.parse(imageUrl))); - } - Calendar calendar = Calendar.getInstance(); - calendar.setTime(pubDate); - metadata.putDate(MediaMetadata.KEY_RELEASE_DATE, calendar); - if (!TextUtils.isEmpty(feedAuthor)) { - metadata.putString(MediaMetadata.KEY_ARTIST, feedAuthor); - } - if (!TextUtils.isEmpty(feedUrl)) { - metadata.putString(CastUtils.KEY_FEED_URL, feedUrl); - } - if (!TextUtils.isEmpty(feedLink)) { - metadata.putString(CastUtils.KEY_FEED_WEBSITE, feedLink); - } - if (!TextUtils.isEmpty(itemIdentifier)) { - metadata.putString(CastUtils.KEY_EPISODE_IDENTIFIER, itemIdentifier); - } else { - metadata.putString(CastUtils.KEY_EPISODE_IDENTIFIER, downloadUrl); - } - if (!TextUtils.isEmpty(episodeLink)) { - metadata.putString(CastUtils.KEY_EPISODE_LINK, episodeLink); - } - String notes = this.notes; - if (notes != null) { - if (notes.length() > CastUtils.EPISODE_NOTES_MAX_LENGTH) { - notes = notes.substring(0, CastUtils.EPISODE_NOTES_MAX_LENGTH); - } - metadata.putString(CastUtils.KEY_EPISODE_NOTES, notes); - } - // Default id value - metadata.putInt(CastUtils.KEY_MEDIA_ID, 0); - metadata.putInt(CastUtils.KEY_FORMAT_VERSION, CastUtils.FORMAT_VERSION_VALUE); - - MediaInfo.Builder builder = new MediaInfo.Builder(downloadUrl) - .setContentType(mime_type) - .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) - .setMetadata(metadata); - if (duration > 0) { - builder.setStreamDuration(duration); - } - return builder.build(); + public void setNotes(String notes) { + this.notes = notes; } public String getEpisodeIdentifier() { @@ -130,6 +86,38 @@ public class RemoteMedia implements Playable { return feedUrl; } + public String getDownloadUrl() { + return downloadUrl; + } + + public String getEpisodeLink() { + return episodeLink; + } + + public String getFeedAuthor() { + return feedAuthor; + } + + public String getImageUrl() { + return imageUrl; + } + + public String getFeedLink() { + return feedLink; + } + + public String getMimeType() { + return mimeType; + } + + public Date getPubDate() { + return pubDate; + } + + public String getNotes() { + return notes; + } + @Override public void writeToPreferences(SharedPreferences.Editor prefEditor) { //it seems pointless to do it, since the session should be kept by the remote device. @@ -196,7 +184,7 @@ public class RemoteMedia implements Playable { @Override public MediaType getMediaType() { - return MediaType.fromMimeType(mime_type); + return MediaType.fromMimeType(mimeType); } @Override @@ -293,7 +281,7 @@ public class RemoteMedia implements Playable { dest.writeString(feedAuthor); dest.writeString(imageUrl); dest.writeString(feedLink); - dest.writeString(mime_type); + dest.writeString(mimeType); dest.writeLong(pubDate.getTime()); dest.writeString(notes); dest.writeInt(duration); @@ -324,9 +312,9 @@ public class RemoteMedia implements Playable { public boolean equals(Object other) { if (other instanceof RemoteMedia) { RemoteMedia rm = (RemoteMedia) other; - return TextUtils.equals(downloadUrl, rm.downloadUrl) && - TextUtils.equals(feedUrl, rm.feedUrl) && - TextUtils.equals(itemIdentifier, rm.itemIdentifier); + return TextUtils.equals(downloadUrl, rm.downloadUrl) + && TextUtils.equals(feedUrl, rm.feedUrl) + && TextUtils.equals(itemIdentifier, rm.itemIdentifier); } if (other instanceof FeedMedia) { FeedMedia fm = (FeedMedia) other; diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 7dee73805..57d0ca38d 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -658,6 +658,7 @@ <!-- Online feed view --> <string name="subscribe_label">Subscribe</string> <string name="subscribing_label">Subscribing…</string> + <string name="preview_episode">Preview</string> <!-- Content descriptions for image buttons --> <string name="rewind_label">Rewind</string> diff --git a/core/src/play/java/de/danoeh/antennapod/core/cast/CastUtils.java b/core/src/play/java/de/danoeh/antennapod/core/cast/CastUtils.java index 88da6a0ec..484904a9a 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/cast/CastUtils.java +++ b/core/src/play/java/de/danoeh/antennapod/core/cast/CastUtils.java @@ -9,6 +9,7 @@ import com.google.android.gms.cast.MediaInfo; import com.google.android.gms.cast.MediaMetadata; import com.google.android.gms.common.images.WebImage; +import de.danoeh.antennapod.core.util.playback.RemoteMedia; import java.util.Calendar; import java.util.List; diff --git a/core/src/play/java/de/danoeh/antennapod/core/cast/MediaInfoCreator.java b/core/src/play/java/de/danoeh/antennapod/core/cast/MediaInfoCreator.java new file mode 100644 index 000000000..91de5418d --- /dev/null +++ b/core/src/play/java/de/danoeh/antennapod/core/cast/MediaInfoCreator.java @@ -0,0 +1,60 @@ +package de.danoeh.antennapod.core.cast; + +import android.net.Uri; +import android.text.TextUtils; +import com.google.android.gms.cast.MediaInfo; +import com.google.android.gms.cast.MediaMetadata; +import com.google.android.gms.common.images.WebImage; +import de.danoeh.antennapod.core.util.playback.RemoteMedia; +import java.util.Calendar; + +public class MediaInfoCreator { + public static MediaInfo from(RemoteMedia media) { + MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC); + + metadata.putString(MediaMetadata.KEY_TITLE, media.getEpisodeTitle()); + metadata.putString(MediaMetadata.KEY_SUBTITLE, media.getFeedTitle()); + if (!TextUtils.isEmpty(media.getImageLocation())) { + metadata.addImage(new WebImage(Uri.parse(media.getImageLocation()))); + } + Calendar calendar = Calendar.getInstance(); + calendar.setTime(media.getPubDate()); + metadata.putDate(MediaMetadata.KEY_RELEASE_DATE, calendar); + if (!TextUtils.isEmpty(media.getFeedAuthor())) { + metadata.putString(MediaMetadata.KEY_ARTIST, media.getFeedAuthor()); + } + if (!TextUtils.isEmpty(media.getFeedUrl())) { + metadata.putString(CastUtils.KEY_FEED_URL, media.getFeedUrl()); + } + if (!TextUtils.isEmpty(media.getFeedLink())) { + metadata.putString(CastUtils.KEY_FEED_WEBSITE, media.getFeedLink()); + } + if (!TextUtils.isEmpty(media.getEpisodeIdentifier())) { + metadata.putString(CastUtils.KEY_EPISODE_IDENTIFIER, media.getEpisodeIdentifier()); + } else { + metadata.putString(CastUtils.KEY_EPISODE_IDENTIFIER, media.getDownloadUrl()); + } + if (!TextUtils.isEmpty(media.getEpisodeLink())) { + metadata.putString(CastUtils.KEY_EPISODE_LINK, media.getEpisodeLink()); + } + String notes = media.getNotes(); + if (notes != null) { + if (notes.length() > CastUtils.EPISODE_NOTES_MAX_LENGTH) { + notes = notes.substring(0, CastUtils.EPISODE_NOTES_MAX_LENGTH); + } + metadata.putString(CastUtils.KEY_EPISODE_NOTES, notes); + } + // Default id value + metadata.putInt(CastUtils.KEY_MEDIA_ID, 0); + metadata.putInt(CastUtils.KEY_FORMAT_VERSION, CastUtils.FORMAT_VERSION_VALUE); + + MediaInfo.Builder builder = new MediaInfo.Builder(media.getDownloadUrl()) + .setContentType(media.getMimeType()) + .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) + .setMetadata(metadata); + if (media.getDuration() > 0) { + builder.setStreamDuration(media.getDuration()); + } + return builder.build(); + } +} diff --git a/core/src/play/java/de/danoeh/antennapod/core/feed/FeedMediaFlavorHelper.java b/core/src/play/java/de/danoeh/antennapod/core/feed/FeedMediaFlavorHelper.java index fe0f771d6..2502f17c0 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/feed/FeedMediaFlavorHelper.java +++ b/core/src/play/java/de/danoeh/antennapod/core/feed/FeedMediaFlavorHelper.java @@ -1,6 +1,6 @@ package de.danoeh.antennapod.core.feed; -import de.danoeh.antennapod.core.cast.RemoteMedia; +import de.danoeh.antennapod.core.util.playback.RemoteMedia; /** * Implements methods for FeedMedia that are flavor dependent. diff --git a/core/src/play/java/de/danoeh/antennapod/core/service/playback/RemotePSMP.java b/core/src/play/java/de/danoeh/antennapod/core/service/playback/RemotePSMP.java index 7c84437e1..2a75f30a2 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/service/playback/RemotePSMP.java +++ b/core/src/play/java/de/danoeh/antennapod/core/service/playback/RemotePSMP.java @@ -15,6 +15,7 @@ import com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastEx import com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException; import com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException; +import de.danoeh.antennapod.core.cast.MediaInfoCreator; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.atomic.AtomicBoolean; @@ -24,7 +25,7 @@ import de.danoeh.antennapod.core.cast.CastConsumer; import de.danoeh.antennapod.core.cast.CastManager; import de.danoeh.antennapod.core.cast.CastUtils; import de.danoeh.antennapod.core.cast.DefaultCastConsumer; -import de.danoeh.antennapod.core.cast.RemoteMedia; +import de.danoeh.antennapod.core.util.playback.RemoteMedia; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.preferences.UserPreferences; @@ -165,7 +166,7 @@ public class RemotePSMP extends PlaybackServiceMediaPlayer { return CastUtils.convertFromFeedMedia((FeedMedia) playable); } if (playable instanceof RemoteMedia) { - return ((RemoteMedia) playable).extractMediaInfo(); + return MediaInfoCreator.from((RemoteMedia) playable); } return null; } |