opt set pip actions

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-06-01 12:46:27 +08:00
parent 9ac37d6fb3
commit 2de59b0c9b
2 changed files with 8 additions and 16 deletions

View File

@@ -183,28 +183,30 @@ public final class AndroidHelper {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
private static void setPipActions(Activity activity, PictureInPictureParams.Builder builder, boolean isLive, boolean isPlaying) { private static void setPipActions(Activity activity, PictureInPictureParams.Builder builder, boolean isLive, boolean isPlaying) {
ComponentName mbrComponent = MediaHelper.getMediaButtonReceiverComponent(activity);
if (mbrComponent == null) return;
ArrayList<RemoteAction> actionList = new ArrayList<>(); ArrayList<RemoteAction> actionList = new ArrayList<>();
if (!isLive) { if (!isLive) {
actionList.add(getRemoteAction(activity, R.drawable.ic_baseline_replay_10_24, "ACTION_REWIND", PlaybackState.ACTION_REWIND)); actionList.add(getRemoteAction(mbrComponent, activity, R.drawable.ic_baseline_replay_10_24, "ACTION_REWIND", PlaybackState.ACTION_REWIND));
} }
if (isPlaying) { if (isPlaying) {
actionList.add(getRemoteAction(activity, android.R.drawable.ic_media_pause, "ACTION_PAUSE", PlaybackState.ACTION_PAUSE)); actionList.add(getRemoteAction(mbrComponent, activity, android.R.drawable.ic_media_pause, "ACTION_PAUSE", PlaybackState.ACTION_PAUSE));
} else { } else {
actionList.add(getRemoteAction(activity, android.R.drawable.ic_media_play, "ACTION_PLAY", PlaybackState.ACTION_PLAY)); actionList.add(getRemoteAction(mbrComponent, activity, android.R.drawable.ic_media_play, "ACTION_PLAY", PlaybackState.ACTION_PLAY));
} }
if (!isLive) { if (!isLive) {
actionList.add(getRemoteAction(activity, R.drawable.ic_baseline_forward_10_24, "ACTION_FAST_FORWARD", PlaybackState.ACTION_FAST_FORWARD)); actionList.add(getRemoteAction(mbrComponent, activity, R.drawable.ic_baseline_forward_10_24, "ACTION_FAST_FORWARD", PlaybackState.ACTION_FAST_FORWARD));
} }
builder.setActions(actionList); builder.setActions(actionList);
} }
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
private static RemoteAction getRemoteAction(Activity activity, @DrawableRes int resId, String title, long action) { private static RemoteAction getRemoteAction(@NonNull ComponentName mbrComponent, Activity activity, @DrawableRes int resId, String title, long action) {
return new RemoteAction( return new RemoteAction(
Icon.createWithResource(activity, resId), Icon.createWithResource(activity, resId),
title, title,
title, title,
Objects.requireNonNull(MediaHelper.buildMediaButtonPendingIntent(activity, action)) Objects.requireNonNull(MediaHelper.buildMediaButtonPendingIntent(activity, mbrComponent, action))
); );
} }

View File

@@ -32,16 +32,6 @@ import java.util.List;
public class MediaHelper { public class MediaHelper {
private static final String TAG = "MediaButtonReceiver"; private static final String TAG = "MediaButtonReceiver";
public static PendingIntent buildMediaButtonPendingIntent(Context context, long action) {
ComponentName mbrComponent = getMediaButtonReceiverComponent(context);
if (mbrComponent == null) {
Log.w(TAG, "A unique media button receiver could not be found in the given context, so "
+ "couldn't build a pending intent.");
return null;
}
return buildMediaButtonPendingIntent(context, mbrComponent, action);
}
public static PendingIntent buildMediaButtonPendingIntent(Context context, ComponentName mbrComponent, long action) { public static PendingIntent buildMediaButtonPendingIntent(Context context, ComponentName mbrComponent, long action) {
if (mbrComponent == null) { if (mbrComponent == null) {
Log.w(TAG, "The component name of media button receiver should be provided."); Log.w(TAG, "The component name of media button receiver should be provided.");