我有一个播放内容的活动播放器,这个活动可以进入图片模式,到目前为止一切正常,但是在Android 13上播放/暂停按钮图标没有更新。
我将在下面公布我的实施情况,
public static PictureInPictureParams buildPIPParams(Context context, boolean nowPlaying, boolean isLive) {
Icon icon;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
if (nowPlaying) {
icon = Icon.createWithResource(context, R.drawable.pause_livetv_ico);
} else {
icon = Icon.createWithResource(context, R.drawable.play_livetv_ico);
}
PendingIntent broadcast = PendingIntent.getBroadcast(context, 0,
new Intent("PIP_PLAY_PAUSE_PLAYER"), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
RemoteAction remoteAction = null;
remoteAction = new RemoteAction(icon, "", "", broadcast);
List<RemoteAction> actions = new ArrayList<>();
actions.add(remoteAction);
Rational aspectRatio = new Rational(16, 9);
PictureInPictureParams build = new PictureInPictureParams.Builder()
.setAspectRatio(aspectRatio)
.setActions(actions)
.build();
return build;
}
}在上面的函数中,我正在构建PictureInPictureParams,并将它传递给enterPictureInPictureMode函数,以便在用户启动PiP模式时设置初始图标,即使在Android13中,这也很好。
然后,当用户按下PiP模式内的播放/暂停按钮时,广播被启动,我暂停/恢复流(这很好),然后通过调用上述函数并将PictureInPictureParams传递给setPictureInPictureParams方法,尝试更新操作的图标为暂停/恢复图标,这在 12及以下的上运行良好,但在android 13上没有工作。
执行情况:
@Override
public void onReceive(Context context, Intent intent) { // on receive PIP_PLAY_PAUSE_PLAYER broadcast event
onPlayButtonClickedWithEvent(false); // this is working fine the stream is being paused/resumed
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
PictureInPictureParams pictureInPictureParams = RTVUtils.buildPIPParams(LiveTVActivity.this, nowPlaying, true);
if (pictureInPictureParams != null)
setPictureInPictureParams(pictureInPictureParams); // this is not working on android 13 devices
}
}
}有人面临这样的问题吗?它是来自android 13操作系统本身吗?谷歌在android 13的发布说明中没有提到这方面的任何更新。
发布于 2022-11-09 09:39:15
解决办法很简单。
编辑以下一行:-
PendingIntent broadcast = PendingIntent.getBroadcast(context, 0,
new Intent("PIP_PLAY_PAUSE_PLAYER"),
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);并将其改为:
PendingIntent broadcast = PendingIntent.getBroadcast(context, nowPlaying?0:1,
new Intent("PIP_PLAY_PAUSE_PLAYER"),
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);这是因为从android 13开始,远程操作需要不同的请求代码来显示不同的图标。
https://stackoverflow.com/questions/73878002
复制相似问题