如何在Android中播放透明视频?

问题描述 投票:3回答:1

我有一个要在Android项目中使用的具有透明背景的视频。我找到了this library,但是它太旧了,性能也不是很好。我如何实现我的目标?

android video transparent alpha
1个回答
0
投票

您可以这样使用videoview;

 <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()
}
© www.soinside.com 2019 - 2024. All rights reserved.