The Picture-in-Picture (PiP) feature allows you to display video content in a small floating window while users interact with other parts of your app. You can show local and remote video streams in the PiP window, or display your own custom UI content. This feature is supported on Android and iOS platforms.
- Custom control style for PiP window (iOS only)
- Automatic PiP mode activation when app goes to background
- Customizable PiP window size and aspect ratio
- Dynamic size/aspect ratio adjustment during active PiP mode
- Support for multiple video streams in PiP mode
- Custom content view integration with PiP window
- Flexible layout configuration for multiple video streams in PiP mode
- iOS: 15.0 and above
- Android: 8.0 and above
-
Declare PiP Support in AndroidManifest.xml
For detailed information, see Add videos using picture-in-picture (PiP)
<activity android:name=".MainActivity" android:supportsPictureInPicture="true" android:configChanges= "screenSize|smallestScreenSize|screenLayout|orientation" ...
Example: AndroidManifest.xml
-
Configure Main Activity
According to the Switch your activity to PiP, automatic PiP mode entry when the app goes to background is only supported on Android 12 and above. For earlier Android versions, you need to explicitly call
enterPictureInPictureMode()inonUserLeaveHint(). This functionality is already implemented inAgoraPIPActivity, so you don't need to implement it yourself. However, if you want to customize the behavior, you can implementAgoraPIPActivityProxyinterface and override its methods in your own activity.import io.agora.rtc.ng.react.AgoraPIPActivity class MainActivity: AgoraPIPActivity() { ... }
Example: MainActivity.kt
-
Configure Media Playback Capability
For detailed information, see Configuring your app for media playback
Steps in Xcode:
- Select your app's target and go to Signing & Capabilities tab
- Click + Capability button
- Add Background Modes capability
- Select "Audio, AirPlay, and Picture in Picture" under Background Modes
Additional Resources:
-
Camera Access in Multitasking Mode (Optional)
Note: You can skip this step if your app doesn't require camera access during multitasking (for example, if you don't need to show the local video stream in the PiP window).
When your app enters a multitasking mode, you should have com.apple.developer.avfoundation.multitasking-camera-access entitlement or set
multitaskingCameraAccessEnabledtotrueof the capture session. Multitasking modes include Slide Over, Split View, and Picture in Picture (PiP).To learn about best practices for using the camera while multitasking, see Accessing the camera while multitasking on iPad.
Requirements:
- iOS < 16: Requires com.apple.developer.avfoundation.multitasking-camera-access entitlement
- Contact Apple for permission
- iOS ≥ 16: Set
multitaskingCameraAccessEnabledtotruein capture session (coming soon)
- iOS < 16: Requires com.apple.developer.avfoundation.multitasking-camera-access entitlement
Complete example: picture_in_picture.tsx
-
iOS User Initiation Requirement
PiP must be initiated by user action on iOS. Programmatic or automatic activation may result in App Store rejection. See Handle User-Initiated Requests
-
Memory Management
- Always dispose
AgoraPipControllerwhen no longer needed - Failure to dispose may result in memory leaks
- Always dispose
-
Control Styles (iOS)
- 0: All system controls (default)
- 1: Hide forward/backward buttons
- 2: Hide play/pause and progress bar (recommended for video conferencing)
- 3: Hide all controls