最近在一个项目中实现视频渲染,用画布的方式,如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的原因
最新推荐文章于 2022-06-09 18:22:55 发布
本文探讨了在视频渲染过程中遇到的声音正常但无画面显示的问题。通过深入分析API文档,发现该问题是由于lockCanvas返回null引起,进一步排查发现底层代码中存在对nativewindow的不当使用。最终通过对代码进行调整解决了这一难题。
6838

被折叠的 条评论
为什么被折叠?



