2

I'm trying to make a video run in the background of my application.

I've searched high and low and the closest thing I could find was this other post: Integrating video file in android app as app background

The code provided does not work (I get 3 errors in java).

Does anyone know how I would go about doing this? I want it to play in the background as I would later like to set a zoom in and out buttons that will allow you to magnify the video playing in the background. Thanks in advance.

2 Answers 2

4

I am not sure whether you can put a video as a background view. But you can try to use a video view and put it inside Frame layout.

You can use this link for further reference: android: video as background view

3
  • Will try this within 24 hours and I'll let you know. Thanks
    – EGHDK
    Mar 10, 2012 at 7:54
  • I couldn't get a video to play in a video view. I tried following some tutorials. No luck so far.
    – EGHDK
    Mar 12, 2012 at 21:11
  • I believe I found my problem. I was trying to set a path for the video in my actual res/raw folder. I need to first save it to SD card it seems, but I was having a problem because my Galaxy Nexus does not have an SD card and the only file system paths I've seen on android started with SDCARD/Something/Folder/File.extension. Thanks
    – EGHDK
    Mar 14, 2012 at 12:50
1

Im using exoplayer to put a video from local:

in 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"/>

in activity or fragment:

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()
}

also realease the component:

override fun onDestroy() {
    super.onDestroy()
    exoPlayerTwo.release()
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.