diff options
Diffstat (limited to 'model/src')
-rw-r--r-- | model/src/main/java/de/danoeh/antennapod/model/MediaMetadataRetrieverCompat.java | 18 | ||||
-rw-r--r-- | model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java | 7 |
2 files changed, 21 insertions, 4 deletions
diff --git a/model/src/main/java/de/danoeh/antennapod/model/MediaMetadataRetrieverCompat.java b/model/src/main/java/de/danoeh/antennapod/model/MediaMetadataRetrieverCompat.java new file mode 100644 index 000000000..f3173946d --- /dev/null +++ b/model/src/main/java/de/danoeh/antennapod/model/MediaMetadataRetrieverCompat.java @@ -0,0 +1,18 @@ +package de.danoeh.antennapod.model; + +import android.media.MediaMetadataRetriever; + +import java.io.IOException; + +/** + * On SDK<29, this class does not have a close method yet, so the app crashes when using try-with-resources. + */ +public class MediaMetadataRetrieverCompat extends MediaMetadataRetriever { + public void close() { + try { + release(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java index 9e8583075..991b5f3db 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java @@ -2,13 +2,13 @@ package de.danoeh.antennapod.model.feed; import android.content.Context; import android.content.SharedPreferences.Editor; -import android.media.MediaMetadataRetriever; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; import androidx.annotation.Nullable; import android.support.v4.media.MediaBrowserCompat; import android.support.v4.media.MediaDescriptionCompat; +import de.danoeh.antennapod.model.MediaMetadataRetrieverCompat; import de.danoeh.antennapod.model.playback.MediaType; import de.danoeh.antennapod.model.playback.Playable; import de.danoeh.antennapod.model.playback.RemoteMedia; @@ -458,11 +458,10 @@ public class FeedMedia extends FeedFile implements Playable { hasEmbeddedPicture = Boolean.FALSE; return; } - MediaMetadataRetriever mmr = new MediaMetadataRetriever(); - try { + try (MediaMetadataRetrieverCompat mmr = new MediaMetadataRetrieverCompat()) { mmr.setDataSource(getLocalMediaUrl()); byte[] image = mmr.getEmbeddedPicture(); - if(image != null) { + if (image != null) { hasEmbeddedPicture = Boolean.TRUE; } else { hasEmbeddedPicture = Boolean.FALSE; |