Android视频透明度不起作用,显示黑色背景
在我正在开发的 Android 应用程序中,我尝试使用 VideoView< 播放具有 透明度 的 WebM 或 MP4 视频/strong> 或 TextureView 但我得到一个黑色背景,但我找不到删除该背景的方法。该视频应该替换大约 200 个动画 png 文件(PNG 大约需要 50MB,我们正在尝试用 0.2MB 视频替换它们)。 到目前为止,我已经测试了 MP4 和 WebM 视频,并且一直得到相同的黑色背景。我以前从未接触过此类视频。有什么想法吗? Java 中的解决方案将非常受欢迎,但我什至 Kotlin 也会这样做。
PS:有什么解决方案可以显示带有 Alpha 通道或色度键的视频吗? iOS 显然可以更好地处理这些事情
In the Android Application I'm working on I'm trying to play a WebM or a MP4 video with transparency using VideoView or TextureView but I get a black background and I couldn't find a way to remove that background. The video is supposed to replace about 200 png files that were animated (the PNGs take about 50MB and we're trying to replace them with a 0.2MB video).
So far I've tested both MP4 and WebM videos and I keep getting the same black background. I haven't worked with this kind of video before. Any thoughts?
A solution in Java would be much appreciated, but I even Kotlin will do.
P.S: Any solution for displaying videos with alpha channel or chroma key? iOS handles these things better apparently
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是
SurfaceView
(VideoView
扩展了它)的工作原理 - 这个View
有点在你的框架布局中切了一个洞,并会渲染一些图形(例如视频帧)以更快的低/本机级别运行,而无需知道 XML 布局中这些View
下放置的内容。因此将 alpha 设置为无操作,因为实际上VideoView
下没有任何内容(因此默认情况下只有黑色背景)。尝试使用TextureView
,它是SurfaceView
的“较新版本”,它应该处理alpha
XML 属性,据我所知,不可能使用 < code>VideoView/
SurfaceView
具有一定的透明度,甚至不更改默认背景颜色 - 您必须编写自己的“渲染引擎”,它将在扩展常见View 的一些自定义小部件上绘制框架
,但我知道你在应用程序级别执行此操作对于设备来说将非常困难且繁重(性能将受到影响)。寻找一种在TextureView
PS 上渲染帧的方法。阅读 DOC 和 这个主题了解这些
View
如何工作(以及原因)的更多细节thats how
SurfaceView
(VideoView
extends it) works - thisView
is kind-of cutting a hole in your framework layout and will render some graphics (e.g. video frames) on way faster low/native level without knowledge what is placed under theseView
s in XML layout. thus setting alpha to it is no-op as in fact there is nothing underVideoView
(so only black background by default). try to useTextureView
, which is a "newer version" ofSurfaceView
, this should handlealpha
XML attributeafaik there is no possibility to use
VideoView
/SurfaceView
with some transparency nor even change default background color - you have to write own "rendering engine" which would draw your frames on some custom widget extending commonView
, but I aware you that doing this on application level will be very hard and heavy for device (performance will suffer). look for a way for rendering your frames onTextureView
PS. read DOC and THIS SO topic for more details how these
View
s works (and why)