Use Media3 MediaStyle instead of legacy one

The default notification provider was still using the legacy
compat MediaStyle instead of our own Media3 one. They are fully
equivalent in their implementation and API and can be swapped out
easily.

PiperOrigin-RevId: 600797920
This commit is contained in:
tonihei 2024-01-23 08:31:34 -08:00 committed by Copybara-Service
parent 0c0b19e26e
commit 9448f939f4
3 changed files with 6 additions and 7 deletions

View File

@ -39,13 +39,13 @@ import androidx.annotation.RequiresApi;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.graphics.drawable.IconCompat; import androidx.core.graphics.drawable.IconCompat;
import androidx.media.app.NotificationCompat.MediaStyle;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.MediaMetadata; import androidx.media3.common.MediaMetadata;
import androidx.media3.common.Player; import androidx.media3.common.Player;
import androidx.media3.common.util.Log; import androidx.media3.common.util.Log;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import androidx.media3.session.MediaStyleNotificationHelper.MediaStyle;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
@ -319,7 +319,7 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId); NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId);
int notificationId = notificationIdProvider.getNotificationId(mediaSession); int notificationId = notificationIdProvider.getNotificationId(mediaSession);
MediaStyle mediaStyle = new MediaStyle(); MediaStyle mediaStyle = new MediaStyle(mediaSession);
int[] compactViewIndices = int[] compactViewIndices =
addNotificationActions( addNotificationActions(
mediaSession, mediaSession,

View File

@ -188,8 +188,8 @@ public final class MediaNotification {
* a service in the <a * a service in the <a
* href="https://developer.android.com/guide/components/foreground-services">foreground</a>. * href="https://developer.android.com/guide/components/foreground-services">foreground</a>.
* It's highly recommended to use a {@linkplain * It's highly recommended to use a {@linkplain
* androidx.media.app.NotificationCompat.MediaStyle media style} {@linkplain Notification * androidx.media3.session.MediaStyleNotificationHelper.MediaStyle media style} {@linkplain
* notification}. * Notification notification}.
*/ */
public MediaNotification(@IntRange(from = 1) int notificationId, Notification notification) { public MediaNotification(@IntRange(from = 1) int notificationId, Notification notification) {
this.notificationId = notificationId; this.notificationId = notificationId;

View File

@ -73,9 +73,8 @@ public class MediaStyleNotificationHelper {
* .setSmallIcon(androidx.media.R.drawable.ic_stat_player) * .setSmallIcon(androidx.media.R.drawable.ic_stat_player)
* .setContentTitle(&quot;Track title&quot;) * .setContentTitle(&quot;Track title&quot;)
* .setContentText(&quot;Artist - Album&quot;) * .setContentText(&quot;Artist - Album&quot;)
* .setLargeIcon(albumArtBitmap)) * .setLargeIcon(albumArtBitmap)
* .setStyle(<b>new NotificationCompat.MediaStyle()</b> * .setStyle(<b>new MediaStyleNotificationHelper.MediaStyle(mySession)</b>)
* .setMediaSession(mySession))
* .build(); * .build();
* </pre> * </pre>
* *