Add remote actions to PiP

If you want to add controls (play, pause, etc.) to your PiP window, create a RemoteAction for each control you want to add.

  1. Add constants for your broadcast controls:
    // Constant for broadcast receiver
    constvalACTION_BROADCAST_CONTROL="broadcast_control"
    // Intent extras for broadcast controls from Picture-in-Picture mode.
    constvalEXTRA_CONTROL_TYPE="control_type"
    constvalEXTRA_CONTROL_PLAY=1
    constvalEXTRA_CONTROL_PAUSE=2
  2. Create a list of RemoteActions for the controls in your PiP window.
  3. Next, add a BroadcastReceiver and override onReceive() to set the actions of each button. Use a DisposableEffect to register the receiver and the remote actions. When the player is disposed, unregister the receiver.
    @RequiresApi(Build.VERSION_CODES.O)
    @Composable
    funPlayerBroadcastReceiver(player:Player?){
    valisInPipMode=rememberIsInPipMode()
    if(!isInPipMode||player==null){
    // Broadcast receiver is only used if app is in PiP mode and player is non null
    return
    }
    valcontext=LocalContext.current
    DisposableEffect(player){
    valbroadcastReceiver:BroadcastReceiver=object:BroadcastReceiver(){
    overridefunonReceive(context:Context?,intent:Intent?){
    if((intent==null)||(intent.action!=ACTION_BROADCAST_CONTROL)){
    return
    }
    when(intent.getIntExtra(EXTRA_CONTROL_TYPE,0)){
    EXTRA_CONTROL_PAUSE->player.pause()
    EXTRA_CONTROL_PLAY->player.play()
    }
    }
    }
    ContextCompat.registerReceiver(
    context,
    broadcastReceiver,
    IntentFilter(ACTION_BROADCAST_CONTROL),
    ContextCompat.RECEIVER_NOT_EXPORTED
    )
    onDispose{
    context.unregisterReceiver(broadcastReceiver)
    }
    }
    }
  4. Pass in a list of your remote actions to the PictureInPictureParams.Builder:
    valcontext=LocalContext.current
    valpipModifier=modifier.onGloballyPositioned{layoutCoordinates->
    valbuilder=PictureInPictureParams.Builder()
    builder.setActions(
    listOfRemoteActions()
    )
    if(shouldEnterPipMode && player!=null && player.videoSize!=VideoSize.UNKNOWN){
    valsourceRect=layoutCoordinates.boundsInWindow().toAndroidRectF().toRect()
    builder.setSourceRectHint(sourceRect)
    builder.setAspectRatio(
    Rational(player.videoSize.width,player.videoSize.height)
    )
    }
    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.S){
    builder.setAutoEnterEnabled(shouldEnterPipMode)
    }
    context.findActivity().setPictureInPictureParams(builder.build())
    }
    VideoPlayer(modifier=pipModifier)

Next steps

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026年08月20日 UTC.