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
(cherry picked from commit 9448f939f4)
This commit is contained in:
tonihei 2024-01-23 08:31:34 -08:00 committed by SheenaChhabra
parent 3a222473e9
commit 236287a513
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.core.app.NotificationCompat;
import androidx.core.graphics.drawable.IconCompat;
import androidx.media.app.NotificationCompat.MediaStyle;
import androidx.media3.common.C;
import androidx.media3.common.MediaMetadata;
import androidx.media3.common.Player;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import androidx.media3.session.MediaStyleNotificationHelper.MediaStyle;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.FutureCallback;
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);
int notificationId = notificationIdProvider.getNotificationId(mediaSession);
MediaStyle mediaStyle = new MediaStyle();
MediaStyle mediaStyle = new MediaStyle(mediaSession);
int[] compactViewIndices =
addNotificationActions(
mediaSession,

View file

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

View file

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