Android 7.0 设置图案解锁,在锁屏状态下拉视频/推送视频,显示黑屏问题分析

版权声明:本文为博主原创文章,未经博主允许不得转载。原文链接http://blog.csdn.net/adayabetter?viewmode=contents https://blog.csdn.net/adayabetter/article/details/80242779

Android 7.0 设置图案解锁,在锁屏状态下拉视频/推送视频,显示黑屏问题分析

如题所述,在Android 7.0上设置图案锁;在锁屏状态下,拉该终端的视频或者像该终端推送视频,可能会出现显示黑屏的问题。


问题分析:视频显示是在SurfaceView上,通过打印日志发现,在拉该终端的视频,终端会打开系统摄像头进行视频采集;设置了camera.setPreviewCallbackWithBuffer回调,在onPreviewFrame中,有每一帧的回调;截图功能是从onPreviewFrame中保存一帧画面,且截图是有画面的,显示当前摄像头采集到的画面,但是界面一直显示为黑屏。从状态栏点击视频传输的Icon,图案解锁成功后,界面显示视频正常。


问题排查分析:
1. 从现象上来看,很像是界面上有一层东西挡住了视频的显示。查看Activity中布局设置,发现在onCreate中先设置了一个空壳布局作为容器,之后才设置真正的布局。修改为直接设置布局,不再套一层显示。
2. 跟踪代码,发现在设置SurfaceView的显示时,surfaceview.setZOrderMediaOverlay为false,修改为true。

surfaceview.setZOrderMediaOverlay方法:

public void setZOrderMediaOverlay(boolean isMediaOverlay) {
        mWindowType = isMediaOverlay
                ? WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY
                : WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
    }


Control whether the surface view's surface is placed on top of its window. Normally it is placed behind the window, to allow it to (for the most part) appear to composite with the views in the hierarchy. By setting this, you cause it to be placed above the window. This means that none of the contents of the window this SurfaceView is in will be visible on top of its surface.
Note that this must be set before the surface view's containing window is attached to the window manager.

Calling this overrides any previous call to setZOrderMediaOverlay(boolean).

经过分析,有如下结论:
1. 在Activity中使用WindowManager进行布局添加调用addView,之后修改布局调用updateViewLayout(例如退到后台,缩小为1像素的点;是为解决在Android 5.1上,调用系统相机传输视频时,退到后台,不会继续录制视频的问题);即使用LayoutInflater.inflate加载布局后,使用WindowManager添加到Window上时,锁屏下拉视频会出现黑屏。
2. 使用setContentView直接设置布局时,显示正常,锁屏下拉视频不会出现黑屏。
3. 最后采用的方案是:
– 3a. 判断机型,在Android 7.0 上时直接调用setContentView设置布局,防止出现黑屏;
– 3b. 在Android 5.1 上使用WindowManager处理addView,updateViewLayout,便于切换到后台时继续视频采集。(注: 5.1上没有黑屏问题,可能是系统侧针对我们的应用做了处理。)
======= 目前还不清楚原因,有待进一步跟踪分析。


总结:以上仅仅是经验分享,实际情况可能有不同;仅供参考,可以从以上提到的地方入手分析,具体情况,具体解决。

猜你喜欢

转载自blog.csdn.net/adayabetter/article/details/80242779
今日推荐