react-native-video: method onBuffer is not exist?

In usage example:

<Video source={{uri: "background"}}   // Can be a URL or a local file.
       ref={(ref) => {
         this.player = ref
       }}                                      // Store reference
       onBuffer={this.onBuffer}                // Callback when remote video is buffering
       onError={this.videoError}               // Callback when video cannot be loaded
       style={styles.backgroundVideo} />

But in Event props onBuffer prop is not exist. And in code is same too. Please delete this from docs or fix onBuffer method work.

P.S. issue#1872

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 27

Most upvoted comments

If you are curois how to enable exoplayer then follow these steps:

  • create react-native.config.js with following content:
module.exports = {
  dependencies: {
    'react-native-video': {
      platforms: {
        android: {
          sourceDir: '../node_modules/react-native-video/android-exoplayer',
        },
      },
    },
  },
};
  • now enable multidex following this tutorial

  • clean using gradlew clean and rebuild to make it work

Try using

onPlaybackStalled={this.handleBuffer.bind(this, { isBuffering: true })} and onPlaybackResume={this.handleBuffer.bind(this, { isBuffering: false })}

We explored the code and found these to be working on version ^4.4.4

Instead of creating react-native.config.js you can use solution from lib readme:

android/settings.gradle

include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')
              onReadyForDisplay={() => {
                console.log('onReadyForDisplay');
                this.setState({
                  loading: false,
                });
                addVideoView(item);
              }}
              onBuffer={() => {
                console.log('onBuffer');
                this.setState({
                  loading: true,
                });
              }}
              onLoad={() => {
                this.setState({
                  paused: false,
                });
              }}
              onProgress={() => {
                // console.log('onProgress ==' + index);
              }}
              onError={(err) => {
                console.log(err);
                alert('Error occured');
              }}

I found out that by default this uses MediaPlayer which doesn’t have onBuffer support but after switching to ExoPlayer it’s working!