Sinch 本地摄像机视图始终保持在顶部

Sinch local camera view always stays on top

我有显示视频的这个视图

<FrameLayout
    android:id="@+id/remoteViewLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/remote_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <RelativeLayout
        android:id="@+id/local_view"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_gravity="bottom|right" />
</FrameLayout>

单击 local_view 后,我需要从两个 RelativeLayout 中删除视图并在不同位置再次添加它们。我正在使用标志来了解当前加载的视图。

private String loadedView = "1";

binding.contentSinchIncomingCall.localView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        if (videoController == null) {
            videoController = mSinchServiceInterface.getVideoController();
        }

        if (loadedView.equals("1")) {
            loadedView = "2";

            ((ViewGroup) videoController.getLocalView().getParent()).removeView(videoController.getLocalView());
            ((ViewGroup) videoController.getRemoteView().getParent()).removeView(videoController.getRemoteView());

            binding.contentSinchIncomingCall.remoteView.addView(videoController.getLocalView());
            binding.contentSinchIncomingCall.localView.addView(videoController.getRemoteView());

            binding.contentSinchIncomingCall.localView.requestLayout();
            binding.contentSinchIncomingCall.localView.invalidate();
            binding.contentSinchIncomingCall.remoteViewLayout.bringChildToFront(binding.contentSinchIncomingCall.localView);

        } else {
            loadedView = "1";

            ((ViewGroup) videoController.getLocalView().getParent()).removeView(videoController.getLocalView());
            ((ViewGroup) videoController.getRemoteView().getParent()).removeView(videoController.getRemoteView());

            binding.contentSinchIncomingCall.remoteView.addView(videoController.getRemoteView());
            binding.contentSinchIncomingCall.localView.addView(videoController.getLocalView());

            binding.contentSinchIncomingCall.localView.requestLayout();
            binding.contentSinchIncomingCall.localView.invalidate();
            binding.contentSinchIncomingCall.remoteViewLayout.bringChildToFront(binding.contentSinchIncomingCall.localView);

        }
    }
});

但在改变位置后,remote_view 重叠local_view。我正在使用 bringChildToFront 方法将 local_view 置于最前面,但仍然无法正常工作。请帮我解决这个问题。

截图:-

由于远程和本地视频都是叠加表面,标准视图层次结构操作 API 如 bringChildToFront 将不起作用。将叠加视图视为视频视图上方所有层中的 'cut' 矩形孔,这使得叠加始终 'onTop'。显然,当两个 'always on top' overlay view 重叠时,就会发生冲突。此问题已在 Sinch Android SDK 3.13.0 中得到解决。请使用 VideoController 的 setLocalVideoZOrder:

Sets whether local video (preview from camera) should be rendered on top of remove video view (default behaviour) or vice versa in case views are overlapping. * @param onTopOfRemoteView if set to false will make remove video rendered on top of preview.

void setLocalVideoZOrder(boolean onTopOfRemoteView);