Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Cannot set VideoView background to transparent

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.

like image 283
George Georgallides Avatar asked Dec 21 '13 15:12

George Georgallides


People also ask

What is VideoView in Android?

android.widget.VideoView. Displays a video file. The VideoView class can load images from various sources (such as resources or content providers), takes care of computing its measurement from the video so that it can be used in any layout manager, and provides various display options such as scaling and tinting.

How do I change the color of the opacity on my Android?

setAlpha(51); Here you can set the opacity between 0 (fully transparent) to 255 (completely opaque). The 51 is exactly the 20% you want.


1 Answers

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

  • https://github.com/Danylo2006/VideoList
  • https://github.com/sprylab/texturevideoview
like image 196
Danylo Volokh Avatar answered Oct 04 '22 22:10

Danylo Volokh