关于Sinch Android SDK v3.12.3本地视频层级覆盖问题的技术咨询
Hey there, I've run into this exact SurfaceView-related quirk with Sinch's SDK before—let's break down why this is happening and how to fix it.
Why the Local Video Keeps Covering Your PiP View
Sinch's default video views use SurfaceView under the hood. On Android, SurfaceView doesn't follow the standard View hierarchy z-ordering: it renders on a separate surface that sits above all regular Views (like your PiP layout) regardless of where you place it in your XML or View tree. That's why even if your PiP view is the last item in your layout, the local SurfaceView still jumps on top.
Solution 1: Switch to TextureView (Recommended)
Sinch SDK v3.12.3 supports using TextureView instead of SurfaceView, which behaves like a regular View and respects your layout's z-order. Here's how to enable it:
// Initialize your Sinch Client as usual SinchClient sinchClient = Sinch.getSinchClientBuilder() .context(getApplicationContext()) .applicationKey("YOUR_APP_KEY") .applicationSecret("YOUR_APP_SECRET") .environmentHost("clientapi.sinch.com") .userId("CURRENT_USER_ID") .build(); // Get the VideoController and enable TextureView VideoController videoController = sinchClient.getVideoController(); videoController.setUseTextureView(true);
Once you enable this, you can arrange your local fullscreen view and remote PiP view in your XML layout as normal—since TextureView follows the View hierarchy, the PiP view (placed last in the layout) will render on top of the fullscreen local view automatically.
Solution 2: Adjust SurfaceView Z-Order (If You Can't Use TextureView)
If you need to stick with SurfaceView for some reason, you can manually adjust their z-axis priority to ensure the PiP view stays on top:
// Fetch the local and remote video views from Sinch View localVideoView = sinchClient.getVideoController().getLocalVideoView(); View remotePiPView = sinchClient.getVideoController().getRemoteVideoView(); // Set a higher translationZ value for the PiP view to push it above the local view remotePiPView.setTranslationZ(15f); localVideoView.setTranslationZ(5f);
Alternatively, if the SurfaceViews are added directly to the Window (some SDKs do this), you can modify their WindowManager.LayoutParams:
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); for (int i = 0; i < windowManager.getChildCount(); i++) { View child = windowManager.getChildAt(i); // Identify Sinch's local SurfaceView (you might need to check tags or class names) if (child instanceof SurfaceView && child.getTag() != null && child.getTag().equals("SinchLocalVideo")) { WindowManager.LayoutParams params = (WindowManager.LayoutParams) child.getLayoutParams(); // Disable overlay priority so other SurfaceViews can sit on top params.zOrderMediaOverlay = false; windowManager.updateViewLayout(child, params); break; } }
Quick Layout Check
Double-check your XML layout to make sure the PiP view is the last child in its parent container. For example:
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!-- Fullscreen Local Video View --> <FrameLayout android:id="@+id/local_video_container" android:layout_width="match_parent" android:layout_height="match_parent"/> <!-- PiP Remote Video View (last child, so it renders on top with TextureView) --> <FrameLayout android:id="@+id/remote_pip_container" android:layout_width="150dp" android:layout_height="200dp" android:layout_gravity="bottom|end" android:layout_margin="16dp"/> </FrameLayout>
Final Notes
TextureView is the most reliable fix here because it eliminates the SurfaceView z-order headache entirely. If you run into any performance concerns (TextureView uses a bit more GPU than SurfaceView), you can tweak hardware acceleration settings for those views, but for most use cases, it's worth the tradeoff for proper layout control.
内容的提问来源于stack exchange,提问作者chpasha

