android videoview 没有图像,Android VideoView神坑,只有声音没有头像解决方法

在Android项目中遇到VideoView显示问题,只播放声音但无图像。经过排查和测试,在StackOverflow找到解决方案,通过设置`setZOrderOnTop(true)`或`setZOrderMediaOverlay(true)`可使VideoView的图像正确显示。调整后,VideoView在窗口中的层级得以修正,解决了图像显示不全的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

具体问题就是,只有声音,但是没有画面。据详细测试,发现图像只在父类布局的底部显示,但是只显示一半,我擦擦,瞬间死了的心都有了。Now,Copy你的代码新建Demo,Ok,又没问题了,但是项目中就是有问题。。。

国内论坛千篇一律,只管BB不讲实际,没法,只有上老外的网站,找到应该是提问问题质量最高的网站-stackoverflow(没有之一),搜索关键字"videoview only audio",出来结果找到下面的代码:

videoView.setZOrderOnTop(true);

this will set the videoview to the top layer; In other words: block everything under it.

然后测试,完美解决。下面还有回答,代码如下:

video_view = (VideoView)findViewById(R.id.video_view);

video_view.setZOrderMediaOverlay(true);

video_view.setVideoPath("/sdcard/myvideo.mp4");

video_view.setMediaController(new MediaController(this));

video_view.start();

video_view.videoView.setZOrderOnTop(true);

核心还是setZOrderMediaOverlay(true)、setZOrderOnTop(true)

SurfaceView的源码,源码的这个方法setZOrderMediaOverlay(boolean isMediaOverlay),源码中对这个方法的描述:

Control whether the surface view‘s surface is placed on top of another regular surface view in the window (but still behind the window itself).This is typically used to place overlays on top of an underlying media surface view.

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 {@link #setZOrderOnTop}.

大概的意思就是说控制窗口中表面的视图层是否放置在常规视图层的顶部。

上面说的那么多,意思就是是不是将SurfaceView放在顶部?毕竟ViewDeoView继承自SurfaceView,显示在顶部没毛病。具体的可以自行google,剩下的也不懂太多了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值