1

I'm trying to use the react-native-video component as follows:

export default class VideoWrapper extends Component<Props> {

  render() {
    return (
        <Video
          source={require('../../assets/test_sound.mp3')}
          ref={player => {
            this.player = player;
          }}
          muted={false}
          repeat={false}
          resizeMode={"cover"}
          volume={1.0}
          rate={1.0}
          ignoreSilentSwitch={"obey"}
          onProgress={this.onProgress}
          onSeek={this.onSeek}
          onEnd={this.onEnd}
          onError={this.onError} 
        />
    );
  }
  onEnd() {
    this.player.seek(0);
  }
  ...

Results in:

ExceptionsManager.js:74 Cannot read property 'seek' of undefined

If I change the onEnd method to the following it works:

onEnd={ () => this.player.seek(0) }

I don't want to use this second approach because it is cluttering up my xml code. How can I fix the first approach?

Chris Snow
  • 23,813
  • 35
  • 144
  • 309

1 Answers1

5

Try this:

onEnd = () => {
    this.player.seek(0);
  };
Hend El-Sahli
  • 6,268
  • 2
  • 25
  • 42