diff options
author | ByteHamster <info@bytehamster.com> | 2023-07-18 17:01:22 +0200 |
---|---|---|
committer | ByteHamster <ByteHamster@users.noreply.github.com> | 2023-07-18 17:57:40 +0200 |
commit | 9f8edd0e9d147ec13532143ae3174d3f71e8219a (patch) | |
tree | 4e86e482e3c1f5e1856de4611c02154f8c815127 /model/src | |
parent | 9be6562b4e4bd4a1487a02a92c68db3625e19d99 (diff) | |
download | AntennaPod-9f8edd0e9d147ec13532143ae3174d3f71e8219a.zip |
Fix MediaMetadataRetriever on API<29
On SDK<29, this class does not have a close method yet, so the app crashes when using try-with-resources.
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; |