在 Android 中设置视频作为背景播放

问题描述 投票:0回答:2

我正在尝试让视频在我的应用程序后台运行。

我到处搜索,我能找到的最接近的是另一篇文章: 在Android应用程序中集成视频文件作为应用程序背景

提供的代码不起作用(我在java中遇到3个错误)。

有谁知道我该怎么做?我希望它在后台播放,因为我稍后想设置一个放大和缩小按钮,以便您放大在后台播放的视频。预先感谢。

java android xml android-layout android-view
2个回答
4
投票

我不确定是否可以将视频作为背景视图。但您可以尝试使用视频视图并将其放入框架布局中。

您可以使用此链接进行进一步参考: android:视频作为背景视图


0
投票

我正在使用 exoplayer 从本地播放视频:

在 xml 中:

<com.google.android.exoplayer2.ui.PlayerView
    android:id="@+id/compensation_video_view"
    android:layout_width="match_parent"
    app:resize_mode="fill"
    android:layout_height="match_parent"/>

在活动或片段中:

private val exoPlayerTwo by lazy(LazyThreadSafetyMode.NONE) {
    SimpleExoPlayer.Builder(requireContext()).build()
}

private fun showBackgroundVideo() {
    //also set to the player view
    binding.compensationVideoView.player = exoPlayerTwo
    exoPlayerTwo.playWhenReady = true
    exoPlayerTwo.volume = 0f
    exoPlayerTwo.repeatMode = SimpleExoPlayer.REPEAT_MODE_ALL // With thi loop the video
    val uri = RawResourceDataSource.buildRawResourceUri(R.raw.compensalia_background_video)
    val mediaItem = MediaItem.fromUri(uri)
    exoPlayerTwo.setMediaItem(mediaItem)
    exoPlayerTwo.prepare()
}

同时释放组件:

override fun onDestroy() {
    super.onDestroy()
    exoPlayerTwo.release()
}
© www.soinside.com 2019 - 2024. All rights reserved.