有没有办法让Android播放具有透明区域的视频?当我尝试在VideoView中播放包含透明区域的WebM视频时,视图的背景仍然是黑色的。我希望在透明区域能够看到父视图的背景而不是黑色。
目前唯一有效的解决方案是将视频帧制作成可绘制动画,但这不太节省内存。
有没有办法让Android播放具有透明区域的视频?当我尝试在VideoView中播放包含透明区域的WebM视频时,视图的背景仍然是黑色的。我希望在透明区域能够看到父视图的背景而不是黑色。
目前唯一有效的解决方案是将视频帧制作成可绘制动画,但这不太节省内存。
<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>
// project's (top level) build.gradle
repositories {
// ...
mavenCentral()
}
// module's build.gradle
dependencies {
// ...
implementation 'io.github.nopol10:alpha-movie:1.3.4'
// ...
}
ffmpeg -vcodec libvpx -i input_video.webm -vf "split [a], pad=iw*2:ih [b], [a] alphaextract, [b] overlay=w" -x264opts keyint=30 -y output_video.mp4
。将input_video.webm和output_video.mp4替换为所需的输入文件和输出文件名。<com.alphamovie.lib.AlphaMovieView
android:id="@+id/video_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
custom:packed="true"
/>
alphaMovieView = (AlphaMovieView) findViewById(R.id.video_player);
alphaMovieView.setVideoFromAssets("output_video.mp4");
这种方法受到AVProVideo中的功能启发。