skip to Main Content

I am working on an app in android studio, and many of my app screens will have looping video backgrounds!! I managed to get it working, but when I run the app on the emulator or a physical device, it stutters for a short amount of time before looping. I thought it could just be the emulator struggling, but the pause happens at a fixed interval. I am very new to android development, so I apologize if I am missing an obvious fix or my code isn’t great. I haven’t been able to find a solution online other than just getting a really long video, which I would prefer not to do to save space. Is there a solution to this problem or do we just have to live with it?

Video: (Hopefully this works!!) (Don’t worry the logo is temporary, they’re doing a great job though and they’re staying somewhere in the app)
Video

Video XML:

<VideoView
        android:id="@+id/vvAuthBackground"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0" />

Video Kotlin:

val path = "android.resource://" + "com.lerstudios.aurelia" + "/" + R.raw.video
vvAuthBackground.setVideoURI(Uri.parse(path))

vvAuthBackground.setOnPreparedListener { mp ->
    mp.start()
    mp.isLooping = true
}

I’m sorry if I did anything wrong, this is also my first time using stack overflow!

2

Answers


  1. I am not familiar to Android development, however I believe I understand your issue. Possibly try another way of generating the images, since that could be causing the lag. Personally, I generate two images and place one before the other. When the first has reached the end of the screen, I move it to be behind the other to create a looping effect with minimal lag. This might not work on Android development. I haven’t tested it but hopefully this helps!

    Login or Signup to reply.
  2. [Renderer]
    The video provided is overall laggy with spikes every 10 sec. Seems like Emulator is decoding video on CPU alone. While your background video is playing you should see a little bit of GPU activity. If its idle then renderer is your culprit. Try changing OpenGL ES renderer settings in emulator extended control under advanced to Desktop native OpenGL. Emulator restart is required for changes to take effect.

    [Codec]
    A heavy encoding format or higher than usual bit rate can cause this. Try a lighter format. HEVC is very heavy try encoding it using H.264 AVC Baseline profile. If its lagging with AVC baseline try MPEG-4 SP as the last resort.

    [physical device]
    Keep in mind a recent device made in the last 8-10 years will have hardware accelerated decoders playing the video without breaking a sweat.

    You don’t have to live with this, Really long video is a really bad solution. From what we see your code is good. Try another physical device. Try different emulator renderer settings.

    If you suspect something in your code you can always create a new project and test the video portion alone.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search