Android: Cannot set VideoView background to transparent
Asked Answered
F

1

14

I have a VideoView playing a video whose shape is not rectangular, (i.e. a rotating cylinder with rounded corners). The videoview is displayed within a LinearLayout that has a background colour. I would like the background of the videoview to be transparent in order to give the effect that the cylinder is rotating on top of the background colour without any black corners. This is what I get: current result

and this is what I want to get:enter image description here

Of course, you could ask, why don't I just set the background colour of the video to match the background colour of the container, but the reason I want to achieve this is because my next step is to have an image or a pattern as the background of the container. My layout xml is the following:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00aaff"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/surface_view"
        android:layout_width="254dp"
        android:layout_height="200px" />

</LinearLayout>

While experimenting, I tried to set a background to the videoview, but that had as a result to obscure the videoview entirely.

Thank you.

Fishbowl answered 21/12, 2013 at 15:21 Comment(0)
E
2

VideoView is opening a separate Window above the current one. This is because it is based on the SurfaceView. And we cannot set alpha or perform animations with it because it is not syncronized with your other UI elements.

So: You should use a video player based on TextureView and animate transparent background by "set alpha" to TextureView You can use these libraries and get a Video Player based on TextureView

Erle answered 25/10, 2015 at 10:46 Comment(1)
If I set alpha, whole video becomes transparency. How can we make only the black background part gone?Tyree

© 2022 - 2024 — McMap. All rights reserved.