react-native-video: Remote videos slow + ANR on Android 9 and 10

Bug

On Android 9 and 10, remotely loaded videos seem to take a very long time to play. Seeking is also extremely slow (changing the seek position will result in the same initial load time).

What’s worse, an ANR can happen while loading. Here’s the ANR stack trace:

ANR ·MainActivity
Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing....

MediaPlayer.java:-2 · android.media.MediaPlayer.setPlaybackParams
--
ReactVideoView.java:470 · com.brentvatne.react.ReactVideoView.setRateModifier
ReactVideoView.java:521 · com.brentvatne.react.ReactVideoView.applyModifiers
ReactVideoView.java:561 · com.brentvatne.react.ReactVideoView.onPrepared
MediaPlayer.java:3346 · android.media.MediaPlayer$EventHandler.handleMessage


Platform

Which player are you experiencing the problem on:

  • Android MediaPlayer

Environment info

React Native: 0.61.5 Library version: “react-native-video”: “5.0.2”

Steps To Reproduce

Load <Video> with the HTTP link provided below. Use on Android 9 or 10 (works fine on Android < 9).

Expected behaviour

Reproducible sample code

Video sample

If possible, include a link to the video that has the problem that can be streamed or downloaded from. https://zinspectordev2.s3.amazonaws.com/usi/2/1576687667933fbdddc5f5458c8b013fef64127c99.mp4

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 5
  • Comments: 16

Most upvoted comments

@pyeonjaesik I just added the required gradle changes (pretty much manual linking). Here’s what I did with RN 0.61 (taken from https://github.com/react-native-community/react-native-video#android-installation)

First add/update react-native.config.js to tell RN to not auto link the module:

module.exports = {
  dependencies: {
    // video we manually link on Android to use exoplayer
    'react-native-video': {
      platforms: {
        android: null
      },
    }
  },
};

Then update settings.gradle to add the dependency:

include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')

Also update build.gradle:

dependencies {
    implementation project(':react-native-video')
    ... others ...
}

Add package to MainApplication.java:

import com.brentvatne.react.ReactVideoPackage;

... other code...

@Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
     
      packages.add(new ReactVideoPackage());

      return packages;
    }

I probably missed something, but the instructions are clear on the link above.

I think there are various buffering and stream setting you can test, but I haven’t tried that at all.

El mié., 12 de febrero de 2020 13:30, pyeonjaesik notifications@github.com escribió:

what do you mean “You may try fine tuning the library settings” ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/react-native-community/react-native-video/issues/1853?email_source=notifications&email_token=ALU263BEZWRYVHPHITUWYGDRCQPZNA5CNFSM4J4OELN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELRNRGY#issuecomment-585291931, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALU263EGB6EQ7UPQT7TQH7DRCQPZNANCNFSM4J4OELNQ .

I solved the issue by manually linking the Android version and using the “exoplayer” version instead. That one works fine; I wonder why it is not the default implementation.

I don’t think you can make it even faster. You may try fine tuning the library settings, or looking at your backend to see if you’re providing a good/fast stream. Other than that, I don’t know 😦

As a last resource, try a webview with a youtube player 😃

@cristianoccazinsp Thank you! I solved this problem. Thanks to your help, remote loading is faster than before. But I want far more faster than this . Can you give me a tip?