mirror of
https://github.com/androidx/media.git
synced 2025-05-16 20:19:57 +08:00
Use resource ID from drawable.xml as the notification icon
Issue: androidx/media#66 Issue: androidx/media#65 #minor-release PiperOrigin-RevId: 452004492
This commit is contained in:
parent
b8ca5b8951
commit
839d4f4390
@ -79,6 +79,8 @@ import java.util.concurrent.ExecutionException;
|
|||||||
* <li><b>{@code media3_notification_pause}</b> - The pause icon.
|
* <li><b>{@code media3_notification_pause}</b> - The pause icon.
|
||||||
* <li><b>{@code media3_notification_seek_to_previous}</b> - The previous icon.
|
* <li><b>{@code media3_notification_seek_to_previous}</b> - The previous icon.
|
||||||
* <li><b>{@code media3_notification_seek_to_next}</b> - The next icon.
|
* <li><b>{@code media3_notification_seek_to_next}</b> - The next icon.
|
||||||
|
* <li><b>{@code media3_notification_small_icon}</b> - The {@link
|
||||||
|
* NotificationCompat.Builder#setSmallIcon(int) small icon}.
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
@ -134,10 +136,18 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
|
|||||||
Player player = mediaSession.getPlayer();
|
Player player = mediaSession.getPlayer();
|
||||||
NotificationCompat.Builder builder =
|
NotificationCompat.Builder builder =
|
||||||
new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
|
new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
|
||||||
|
|
||||||
|
MediaStyle mediaStyle = new MediaStyle();
|
||||||
|
int[] compactViewIndices =
|
||||||
|
addNotificationActions(
|
||||||
|
getMediaButtons(player.getAvailableCommands(), customLayout, player.getPlayWhenReady()),
|
||||||
|
builder,
|
||||||
|
actionFactory);
|
||||||
|
mediaStyle.setShowActionsInCompactView(compactViewIndices);
|
||||||
|
|
||||||
// Set metadata info in the notification.
|
// Set metadata info in the notification.
|
||||||
MediaMetadata metadata = player.getMediaMetadata();
|
MediaMetadata metadata = player.getMediaMetadata();
|
||||||
builder.setContentTitle(metadata.title).setContentText(metadata.artist);
|
builder.setContentTitle(metadata.title).setContentText(metadata.artist);
|
||||||
|
|
||||||
@Nullable ListenableFuture<Bitmap> bitmapFuture = loadArtworkBitmap(metadata);
|
@Nullable ListenableFuture<Bitmap> bitmapFuture = loadArtworkBitmap(metadata);
|
||||||
if (bitmapFuture != null) {
|
if (bitmapFuture != null) {
|
||||||
if (bitmapFuture.isDone()) {
|
if (bitmapFuture.isDone()) {
|
||||||
@ -161,13 +171,6 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaStyle mediaStyle = new MediaStyle();
|
|
||||||
int[] compactViewIndices =
|
|
||||||
addNotificationActions(
|
|
||||||
getMediaButtons(player.getAvailableCommands(), customLayout, player.getPlayWhenReady()),
|
|
||||||
builder,
|
|
||||||
actionFactory);
|
|
||||||
mediaStyle.setShowActionsInCompactView(compactViewIndices);
|
|
||||||
if (player.isCommandAvailable(COMMAND_STOP) || Util.SDK_INT < 21) {
|
if (player.isCommandAvailable(COMMAND_STOP) || Util.SDK_INT < 21) {
|
||||||
// We must include a cancel intent for pre-L devices.
|
// We must include a cancel intent for pre-L devices.
|
||||||
mediaStyle.setCancelButtonIntent(actionFactory.createMediaActionPendingIntent(COMMAND_STOP));
|
mediaStyle.setCancelButtonIntent(actionFactory.createMediaActionPendingIntent(COMMAND_STOP));
|
||||||
@ -185,7 +188,7 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
|
|||||||
.setContentIntent(mediaSession.getSessionActivity())
|
.setContentIntent(mediaSession.getSessionActivity())
|
||||||
.setDeleteIntent(actionFactory.createMediaActionPendingIntent(COMMAND_STOP))
|
.setDeleteIntent(actionFactory.createMediaActionPendingIntent(COMMAND_STOP))
|
||||||
.setOnlyAlertOnce(true)
|
.setOnlyAlertOnce(true)
|
||||||
.setSmallIcon(getSmallIconResId(context))
|
.setSmallIcon(R.drawable.media3_notification_small_icon)
|
||||||
.setStyle(mediaStyle)
|
.setStyle(mediaStyle)
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
.setOngoing(false)
|
.setOngoing(false)
|
||||||
@ -385,15 +388,6 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getSmallIconResId(Context context) {
|
|
||||||
int appIcon = context.getApplicationInfo().icon;
|
|
||||||
if (appIcon != 0) {
|
|
||||||
return appIcon;
|
|
||||||
} else {
|
|
||||||
return Util.SDK_INT >= 21 ? R.drawable.media_session_service_notification_ic_music_note : 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static long getPlaybackStartTimeEpochMs(Player player) {
|
private static long getPlaybackStartTimeEpochMs(Player player) {
|
||||||
// Changing "showWhen" causes notification flicker if SDK_INT < 21.
|
// Changing "showWhen" causes notification flicker if SDK_INT < 21.
|
||||||
if (Util.SDK_INT >= 21
|
if (Util.SDK_INT >= 21
|
||||||
|
Loading…
x
Reference in New Issue
Block a user