Two fixes for setMetadata

This commit is contained in:
Robin 2021-09-24 15:00:37 +02:00 committed by litetex
parent f36fd2f7b2
commit b2e2551e33
2 changed files with 44 additions and 5 deletions

View File

@ -1626,8 +1626,12 @@ public final class Player implements
final boolean showThumbnail = prefs.getBoolean(
context.getString(R.string.show_thumbnail_key), true);
// setMetadata only updates the metadata when any of the metadata keys are null
mediaSessionManager.setMetadata(getVideoTitle(), getUploaderName(),
showThumbnail ? getThumbnail() : null, duration);
if (showThumbnail) {
mediaSessionManager.setMetadata(getVideoTitle(), getUploaderName(), getThumbnail(),
duration);
} else {
mediaSessionManager.setMetadata(getVideoTitle(), getUploaderName(), duration);
}
}
private void startProgressLoop() {
@ -3023,9 +3027,11 @@ public final class Player implements
@Nullable
public Bitmap getThumbnail() {
return currentThumbnail == null
? BitmapFactory.decodeResource(context.getResources(), R.drawable.dummy_thumbnail)
: currentThumbnail;
if (currentThumbnail == null) {
currentThumbnail = BitmapFactory.decodeResource(
context.getResources(), R.drawable.dummy_thumbnail);
}
return currentThumbnail;
}
//endregion

View File

@ -65,6 +65,39 @@ public class MediaSessionManager {
return mediaSession.getSessionToken();
}
public void setMetadata(final String title,
final String artist,
final long duration) {
if (!mediaSession.isActive()) {
return;
}
if (DEBUG) {
if (getMetadataTitle() == null) {
Log.d(TAG, "N_getMetadataTitle: title == null");
}
if (getMetadataArtist() == null) {
Log.d(TAG, "N_getMetadataArtist: artist == null");
}
if (getMetadataDuration() <= 1) {
Log.d(TAG, "N_getMetadataDuration: duration <= 1; " + getMetadataDuration());
}
}
if (getMetadataTitle() == null || getMetadataArtist() == null || getMetadataDuration() <= 1
|| !getMetadataTitle().equals(title)) {
if (DEBUG) {
Log.d(TAG, "setMetadata: N_Metadata update: t: " + title + " a: " + artist
+ " d: " + duration);
}
mediaSession.setMetadata(new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, title)
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration).build());
}
}
public void setMetadata(final String title,
final String artist,
final Bitmap albumArt,