如何在Android中播放透明视频



我有一个透明背景的视频,我想在我的Android项目中使用。我找到了这个库,但它太旧了,性能也不太好。我该如何实现我的目标?

您可以像这样使用视频视图;

<VideoView
android:id="@+id/video_background"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation_bar"
app:layout_constraintEnd_toEndOf="parent"
android:background="@color/transparent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

在你的活动中;

videoBackgroundView = findViewById(R.id.video_background)
val path = "android.resource://com.example.xxxxx" + "/" + R.raw.video
videoBackgroundView?.setVideoPath(path)
videoBackgroundView?.setOnPreparedListener { mp ->
mp.isLooping = true
videoBackgroundView?.start()
}

最新更新