Android:媒体通知

问题描述 投票:0回答:1

我正在开发一个音乐应用程序,我正在使用媒体操作按钮在通知上显示媒体详细信息,现在当我在 Android 12 上运行我的应用程序时,我看到一切都按预期工作,但在 Android 13 上,我看不到下一个和上一个操作按钮。

我哪里出错了?以下是截图,方便参考。

Notification notification = new NotificationCompat.Builder(mContext, CHANNEL_ONE_ID)
                .setSmallIcon(R.mipmap.ic_music)
                .setContentTitle(title)
                .setContentText(description)
                .setContentIntent(actionOnClick)
                .setLargeIcon(bitmap)
                .setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
                        .setShowActionsInCompactView(0, currSong.isCurrentPlaying() ? 1 : 3, 2)
                        .setMediaSession(mediaSession.getSessionToken()))
                .addAction(new NotificationCompat.Action(R.drawable.ic_music_previous,
                        "Previous",
                        MediaButtonReceiver.buildMediaButtonPendingIntent(mContext,
                                PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)))
                .addAction(new NotificationCompat.Action(PlayerConstants.SONG_PAUSED ? R.drawable.ic_music_play : R.drawable.ic_music_pause,
                        PlayerConstants.SONG_PAUSED ? "Play" : "Pause",
                        MediaButtonReceiver.buildMediaButtonPendingIntent(mContext,
                                PlayerConstants.SONG_PAUSED ? PlaybackStateCompat.ACTION_PLAY : PlaybackStateCompat.ACTION_PAUSE)))
                .addAction(new NotificationCompat.Action(R.drawable.ic_music_next,
                        "Next",
                        MediaButtonReceiver.buildMediaButtonPendingIntent(mContext,
                                PlaybackStateCompat.ACTION_SKIP_TO_NEXT)))
                .setAutoCancel(false)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .build();

        getNotificationManager().notify(1, notification);
android exoplayer android-music-player
1个回答
0
投票

从 Android 13+ 开始,您需要使用媒体会话来支持媒体操作。 检查文档: https://developer.android.com/media/implement/surfaces/mobile

© www.soinside.com 2019 - 2024. All rights reserved.