Android video transparency doesn't work, black background displayed

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

Upvotes: 2

Views: 1196

Answers (1)

snachmsm
snachmsm

Reputation: 19223

thats how SurfaceView (VideoView extends it) works - this View 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 these Views in XML layout. thus setting alpha to it is no-op as in fact there is nothing under VideoView (so only black background by default). try to use TextureView, which is a "newer version" of SurfaceView, this should handle alpha XML attribute

afaik 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 common View, 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 on TextureView

PS. read DOC and THIS SO topic for more details how these Views works (and why)

Upvotes: 1

Related Questions