mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2026-08-18 11:05:49 +00:00
Try to reduce memory consumption (#8539)
### Description Try to reduce memory consumption - Initialize the data source factory only once - Do not hand out cover images to media sessions (Android Auto, etc) ### Checklist <!-- To help us keep the issue tracker clean and work as efficient as possible, please make sure that you have done all of the following. You can tick the boxes below by placing an x inside the brackets like this: [x] --> - [x] I have read the contribution guidelines: https://github.com/AntennaPod/AntennaPod/blob/develop/CONTRIBUTING.md#submit-a-pull-request - [x] I have performed a self-review of my code, going through my changes line by line and carefully considering why this line change is necessary - [x] I have run the automated code checks using `./gradlew checkstyle lint` - [x] My code follows the style guidelines of the AntennaPod project: https://antennapod.org/contribute/develop/app/code-style - [x] I have mentioned the corresponding issue and the relevant keyword (e.g., "Closes: #xy") in the description (see https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) - [x] If it is a core feature, I have added automated tests
This commit is contained in:
committed by
GitHub
parent
c789cc03ea
commit
f9ca0e55bb
@ -55,7 +55,7 @@ public class MediaItemAdapter {
|
||||
* Create a media item and load all its metadata, including cover art using Glide.
|
||||
* Do NOT use this method on the main thread.
|
||||
*/
|
||||
public static MediaItem fromPlayable(Context context, Playable playable) {
|
||||
public static MediaItem fromPlayable(Context context, Playable playable, boolean forBrowse) {
|
||||
ThreadUtils.assertNotMainThread();
|
||||
MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();
|
||||
metadataBuilder.setTitle(playable.getEpisodeTitle());
|
||||
@ -69,13 +69,18 @@ public class MediaItemAdapter {
|
||||
metadataBuilder.setSubtitle(feedMedia.getFeedTitle());
|
||||
metadataBuilder.setArtist(feedMedia.getFeedTitle());
|
||||
}
|
||||
int iconSize = (int) (128 * context.getResources().getDisplayMetrics().density);
|
||||
Bitmap bitmap = loadArtworkBitmap(context, playable, iconSize);
|
||||
if (bitmap != null) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bos);
|
||||
metadataBuilder.setArtworkData(bos.toByteArray(), MediaMetadata.PICTURE_TYPE_FRONT_COVER);
|
||||
} else if (playable.getImageLocation() != null && playable.getImageLocation().startsWith("http")) {
|
||||
boolean useUri = true;
|
||||
if (!forBrowse) {
|
||||
int iconSize = (int) (128 * context.getResources().getDisplayMetrics().density);
|
||||
Bitmap bitmap = loadArtworkBitmap(context, playable, iconSize);
|
||||
if (bitmap != null) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
|
||||
metadataBuilder.setArtworkData(bos.toByteArray(), MediaMetadata.PICTURE_TYPE_FRONT_COVER);
|
||||
useUri = false;
|
||||
}
|
||||
}
|
||||
if (useUri && playable.getImageLocation() != null && playable.getImageLocation().startsWith("http")) {
|
||||
metadataBuilder.setArtworkUri(Uri.parse(playable.getImageLocation()));
|
||||
}
|
||||
Bundle extras = new Bundle();
|
||||
@ -226,7 +231,7 @@ public class MediaItemAdapter {
|
||||
for (FeedItem item : feedItems) {
|
||||
FeedMedia media = item.getMedia();
|
||||
if (media != null && (media.localFileAvailable() || media.getStreamUrl() != null)) {
|
||||
itemsBuilder.add(MediaItemAdapter.fromPlayable(context, media));
|
||||
itemsBuilder.add(fromPlayable(context, media, true));
|
||||
}
|
||||
}
|
||||
return itemsBuilder.build();
|
||||
|
||||
@ -633,7 +633,7 @@ public class Media3PlaybackService extends MediaLibraryService {
|
||||
queueLoaderDisposable = Maybe.fromCallable(() -> {
|
||||
FeedItem nextItem = DBReader.getNextInQueue(item);
|
||||
if (nextItem != null && nextItem.getMedia() != null) {
|
||||
return new Pair<>(nextItem.getMedia(), MediaItemAdapter.fromPlayable(Media3PlaybackService.this, nextItem.getMedia()));
|
||||
return new Pair<>(nextItem.getMedia(), MediaItemAdapter.fromPlayable(Media3PlaybackService.this, nextItem.getMedia(), false));
|
||||
}
|
||||
return null;
|
||||
})
|
||||
|
||||
@ -115,15 +115,14 @@ public class ExoPlayerUtils {
|
||||
@NonNull
|
||||
@Override
|
||||
public MediaSource createMediaSource(@NonNull MediaItem mediaItem) {
|
||||
DefaultMediaSourceFactory factory = new DefaultMediaSourceFactory(
|
||||
buildDataSourceFactory(mediaItem), extractorsFactory);
|
||||
defaultFactory.setDataSourceFactory(buildDataSourceFactory(mediaItem));
|
||||
if (loadErrorHandlingPolicy != null) {
|
||||
factory.setLoadErrorHandlingPolicy(loadErrorHandlingPolicy);
|
||||
defaultFactory.setLoadErrorHandlingPolicy(loadErrorHandlingPolicy);
|
||||
}
|
||||
if (drmSessionManagerProvider != null) {
|
||||
factory.setDrmSessionManagerProvider(drmSessionManagerProvider);
|
||||
defaultFactory.setDrmSessionManagerProvider(drmSessionManagerProvider);
|
||||
}
|
||||
return factory.createMediaSource(mediaItem);
|
||||
return defaultFactory.createMediaSource(mediaItem);
|
||||
}
|
||||
|
||||
private DataSource.Factory buildDataSourceFactory(MediaItem mediaItem) {
|
||||
|
||||
@ -337,7 +337,8 @@ public class MediaLibrarySessionCallback implements MediaLibraryService.MediaLib
|
||||
(int) startPosition, media.getLastPlayedTimeStatistics());
|
||||
MediaSession.MediaItemsWithStartPosition result =
|
||||
new MediaSession.MediaItemsWithStartPosition(
|
||||
Collections.singletonList(MediaItemAdapter.fromPlayable(context, media)),
|
||||
Collections.singletonList(
|
||||
MediaItemAdapter.fromPlayable(context, media, false)),
|
||||
0, startPosition);
|
||||
future.set(result);
|
||||
},
|
||||
@ -485,7 +486,7 @@ public class MediaLibrarySessionCallback implements MediaLibraryService.MediaLib
|
||||
try {
|
||||
long mediaId = Long.parseLong(item.mediaId);
|
||||
FeedMedia media = DBReader.getFeedMedia(mediaId);
|
||||
builder.add(MediaItemAdapter.fromPlayable(context, media));
|
||||
builder.add(MediaItemAdapter.fromPlayable(context, media, false));
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "Invalid media ID: " + item.mediaId, e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user