Target Android 13 (#6409)

This commit is contained in:
ByteHamster 2023-04-03 21:51:54 +02:00 committed by GitHub
parent 3e101cca2a
commit 9b989fed43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 39 deletions

View File

@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<supports-screens
android:anyDensity="true"

View File

@ -1,9 +1,9 @@
android {
compileSdk 31
compileSdk 33
defaultConfig {
minSdk 21
targetSdk 31
targetSdk 33
multiDexEnabled true
vectorDrawables.useSupportLibrary true

View File

@ -199,48 +199,48 @@ public class LocalFeedUpdater {
return item;
}
private static void loadMetadata(FeedItem item, FastDocumentFile file, Context context) {
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(context, file.getUri());
private static void loadMetadata(FeedItem item, FastDocumentFile file, Context context) throws IOException {
try (MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever()) {
mediaMetadataRetriever.setDataSource(context, file.getUri());
String dateStr = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE);
if (!TextUtils.isEmpty(dateStr)) {
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.getDefault());
item.setPubDate(simpleDateFormat.parse(dateStr));
} catch (ParseException parseException) {
Date date = DateUtils.parse(dateStr);
if (date != null) {
item.setPubDate(date);
String dateStr = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE);
if (!TextUtils.isEmpty(dateStr)) {
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.getDefault());
item.setPubDate(simpleDateFormat.parse(dateStr));
} catch (ParseException parseException) {
Date date = DateUtils.parse(dateStr);
if (date != null) {
item.setPubDate(date);
}
}
}
}
String title = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
if (!TextUtils.isEmpty(title)) {
item.setTitle(title);
}
String title = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
if (!TextUtils.isEmpty(title)) {
item.setTitle(title);
}
String durationStr = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
item.getMedia().setDuration((int) Long.parseLong(durationStr));
String durationStr = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
item.getMedia().setDuration((int) Long.parseLong(durationStr));
item.getMedia().setHasEmbeddedPicture(mediaMetadataRetriever.getEmbeddedPicture() != null);
mediaMetadataRetriever.close();
try (InputStream inputStream = context.getContentResolver().openInputStream(file.getUri())) {
Id3MetadataReader reader = new Id3MetadataReader(
new CountingInputStream(new BufferedInputStream(inputStream)));
reader.readInputStream();
item.setDescriptionIfLonger(reader.getComment());
} catch (IOException | ID3ReaderException e) {
Log.d(TAG, "Unable to parse ID3 of " + file.getUri() + ": " + e.getMessage());
item.getMedia().setHasEmbeddedPicture(mediaMetadataRetriever.getEmbeddedPicture() != null);
try (InputStream inputStream = context.getContentResolver().openInputStream(file.getUri())) {
VorbisCommentMetadataReader reader = new VorbisCommentMetadataReader(inputStream);
Id3MetadataReader reader = new Id3MetadataReader(
new CountingInputStream(new BufferedInputStream(inputStream)));
reader.readInputStream();
item.setDescriptionIfLonger(reader.getDescription());
} catch (IOException | VorbisCommentReaderException e2) {
Log.d(TAG, "Unable to parse vorbis comments of " + file.getUri() + ": " + e2.getMessage());
item.setDescriptionIfLonger(reader.getComment());
} catch (IOException | ID3ReaderException e) {
Log.d(TAG, "Unable to parse ID3 of " + file.getUri() + ": " + e.getMessage());
try (InputStream inputStream = context.getContentResolver().openInputStream(file.getUri())) {
VorbisCommentMetadataReader reader = new VorbisCommentMetadataReader(inputStream);
reader.readInputStream();
item.setDescriptionIfLonger(reader.getDescription());
} catch (IOException | VorbisCommentReaderException e2) {
Log.d(TAG, "Unable to parse vorbis comments of " + file.getUri() + ": " + e2.getMessage());
}
}
}
}

View File

@ -62,9 +62,8 @@ public class MediaDownloadedHandler implements Runnable {
ChapterUtils.loadChaptersFromUrl(media.getItem().getPodcastIndexChapterUrl(), false);
}
// Get duration
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
String durationStr = null;
try {
try (MediaMetadataRetriever mmr = new MediaMetadataRetriever()) {
mmr.setDataSource(media.getFile_url());
durationStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
media.setDuration(Integer.parseInt(durationStr));
@ -73,8 +72,6 @@ public class MediaDownloadedHandler implements Runnable {
Log.d(TAG, "Invalid file duration: " + durationStr);
} catch (Exception e) {
Log.e(TAG, "Get duration failed", e);
} finally {
mmr.release();
}
final FeedItem item = media.getItem();