Video with transparency on Android

2019-06-15 07:43发布

问题:

Is there any way to have Android play video with transparent areas? When I try to play a WebM video containing transparent areas in VideoView, the background of the view remains black. Instead of black I'd expect to see the background of the parent view shown through on the transparent areas.

The only working solution I've found so far is to create a drawable animation out of the video frames, which isn't very memory efficient.

回答1:

I know it's a bit late, but perhaps it can help nevertheless.

The best way I can think of for achieving this is using OpenGL ES - you render the video through a surface, and write a small shader that removes the color areas you want removed. You can find several examples for this technique on the web, perhaps this link can provide some kickstart: First steps in creating a chroma key effect using android camera



回答2:

I think this will overcome your problem Try this https://github.com/pavelsemak/alpha-movie

Here is the demo example,

<RelativeLayout
                android:id="@+id/mainContent"
                android:layout_width="match_parent"
                android:layout_height="200dp">

                <ImageView
                    android:id="@+id/imageView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="fitXY"
                    android:src="@drawable/bg1" />

                <com.alphamovie.lib.AlphaMovieView
                    android:id="@+id/alpha_video_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_centerInParent="true"
                    app:accuracy="0.7"
                    app:alphaColor="#000000"/>

            </RelativeLayout>


标签: android webm vp8