Fix Chromecast crash if FeedItem does not have a feed (#6541)

This commit is contained in:
ByteHamster 2023-07-15 22:03:50 +02:00 committed by GitHub
parent 8d1eb62f0b
commit f1f3674230
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.playback.cast;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.Nullable;
import com.google.android.gms.cast.MediaInfo; import com.google.android.gms.cast.MediaInfo;
import com.google.android.gms.cast.MediaMetadata; import com.google.android.gms.cast.MediaMetadata;
import com.google.android.gms.common.images.WebImage; import com.google.android.gms.common.images.WebImage;
@ -74,7 +75,6 @@ public class MediaInfoCreator {
MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC); MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC);
if (media.getItem() == null) { if (media.getItem() == null) {
throw new IllegalStateException("item is null"); throw new IllegalStateException("item is null");
//media.setItem(DBReader.getFeedItem(media.getItemId()));
} }
FeedItem feedItem = media.getItem(); FeedItem feedItem = media.getItem();
if (feedItem != null) { if (feedItem != null) {
@ -84,15 +84,15 @@ public class MediaInfoCreator {
metadata.putString(MediaMetadata.KEY_SUBTITLE, subtitle); metadata.putString(MediaMetadata.KEY_SUBTITLE, subtitle);
} }
final @Nullable Feed feed = feedItem.getFeed();
// Manual because cast does not support embedded images // Manual because cast does not support embedded images
String url = feedItem.getImageUrl() == null ? feedItem.getFeed().getImageUrl() : feedItem.getImageUrl(); String url = (feedItem.getImageUrl() == null && feed != null) ? feed.getImageUrl() : feedItem.getImageUrl();
if (!TextUtils.isEmpty(url)) { if (!TextUtils.isEmpty(url)) {
metadata.addImage(new WebImage(Uri.parse(url))); metadata.addImage(new WebImage(Uri.parse(url)));
} }
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(media.getItem().getPubDate()); calendar.setTime(media.getItem().getPubDate());
metadata.putDate(MediaMetadata.KEY_RELEASE_DATE, calendar); metadata.putDate(MediaMetadata.KEY_RELEASE_DATE, calendar);
Feed feed = feedItem.getFeed();
if (feed != null) { if (feed != null) {
if (!TextUtils.isEmpty(feed.getAuthor())) { if (!TextUtils.isEmpty(feed.getAuthor())) {
metadata.putString(MediaMetadata.KEY_ARTIST, feed.getAuthor()); metadata.putString(MediaMetadata.KEY_ARTIST, feed.getAuthor());