首页 > 代码库 > lockCanvas为NULL的原因

lockCanvas为NULL的原因

        最近在一个项目中实现视频渲染,用画布的方式,如mcanvas = mSurface.lockCanvas(null);报了java.lang.NullPointerException mCanvas==null,  从而出现播放视频是有声音没画面啊,代码左推敲右推敲,都找不到用法不恰当的地方,在google里搜寻都无法找到解决方法。最后想到来看看它的API说明,从文档中看到有这么描述: Start editing the pixels in the surface. The returned Canvas can be used to draw into the surface‘s bitmap.A null is returned if the surface has not been created or otherwise cannot be edited. You will usually need to implement Callback.surfaceCreated to find out when the Surface is available for use.这么说明当lockCanvas为空不就两种情况要么没创建成功要么在别的程序里正编辑呢,很明显是后面这种情况,最终找到了在我们的底层代码里有使用nativewindown来做显示,所以就游刃而解了。

lockCanvas为NULL的原因