Android two surfaceView overlays are not displayed, the small video window is blocked, there is sound but no picture

background:

In today's social media, the proportion of short videos and live broadcasts is still relatively high. We normally use single-window short videos and multi-windows that support small windows. The ideal state of multi-windows is that the large window is at the bottom and the small window is at the bottom. Above, similar to WeChat video.

question:

In our development, we arrange according to the layer layout, often put the large video at the bottom, and the small video window on top of the large window. This prevents the small window from being blocked by the large window, but some models are different from what we think.

1. When we are dealing with microphone connection, especially video connection or video call, there is a large window and a small window. During the debugging process, we found that the small window has sound but no picture or no display, only the large window surfaceView The normal display is because the large window of the surfaceView of some devices blocks the small window.

reason:

It is because the surfaceView is an independent window window. Even if you set the display hierarchy in the layout, the surfaceView is not controlled by the window of the Activity. Therefore, in this case, we need to set our code when displaying, and specify which priority is in upper layer.

private void initSetSurFaceViewHolder(SurfaceView surfaceView) {
    SurfaceHolder holder = surfaceView.getHolder();
    if (holder == null)
        return;
    holder.setKeepScreenOn(true);
    holder.setFormat(PixelFormat.TRANSPARENT);
    surfaceView.setZOrderOnTop(true);
    surfaceView.setZOrderMediaOverlay(true);

}

SurfaceView provides layer management, which can bring the system window where it is located to top. After doing this manually, we can

The small control window always floats above the large window.

Guess you like

Origin blog.csdn.net/qq36246172/article/details/112572982