question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to access seek()? Refs don't appear to be returned.

See original GitHub issue

I am trying to get a reference to my player by passing ref={component => this._videoPlayer = component} to it but that doesn’t appear to ever be called so I don’t have a reference to the component to call .seek() on.

if (!!this._videoPlayer) {
      this._videoPlayer.seek(val);
    }

Is the ref functionality broken or am I misunderstanding how I should call seek()?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
benjamincarpcommented, Sep 26, 2016

Wrapping the Video component in a View component did seem to make the ref work. I don’t understand it at all, but it worked.

 <View style={styles.container}>
        <TouchableHighlight style={styles.fullScreen} onPress={() => {this.setState({paused: !this.state.paused})}}>
          <View style={styles.fullScreen}><Video
            source={{uri: uri}}
            style={styles.fullScreen}
            rate={this.state.rate}
            paused={this.state.paused}
            volume={this.state.volume}
            muted={this.state.muted}
            resizeMode={this.state.resizeMode}
            onLoad={this.onLoad}
            onProgress={this.onProgress}
            onEnd={() => {this.state.paused = true}}
            repeat={true}
            ref={(component) => {this._videoPlayer = component}}
          /></View>
        </TouchableHighlight>
        {controls}
        <BackButton style={{position: 'absolute', top: 10, left: 10 }}/>
      </View>

Get rid of the view between the TouchableHighlight and Video and Ref no longer works. Strange.

2reactions
heatnodecommented, Sep 19, 2016

Just a note since I came across this looking for seek usage examples. Refs seem to work now. I’m using RN 0.33. The code below works and is based on the example VideoPlayer class:

//added this to one of the control sections
  renderSeekControl() {
      const isSelected = false;
      return (
          <TouchableOpacity onPress={() => {this.handleSeekClick() } }>
              <Text style={[styles.controlOption, { fontWeight: isSelected ? "bold" : "normal" }]}>
                  Seek Test
              </Text>
          </TouchableOpacity>
      )
  }

  handleSeekClick() {
      // seek test
      if (this._videoRef !== null) {
          console.log("seeking");
          this._videoRef.seek(0);
      }
  }
renderCustomSkin() {
...
    return (
      <View style={styles.container}>
        <TouchableOpacity style={styles.fullScreen} onPress={() => {this.setState({paused: !this.state.paused})}}>
          <Video
            ref={(ref) => this._videoRef = ref}
            style={styles.fullScreen}
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to access seek()? Refs don't appear to be returned. #298
I am trying to get a reference to my player by passing ref={component => this._videoPlayer = component} to it but that doesn't appear...
Read more >
Unable to access $refs in component method - Stack Overflow
When clicking the "Click me" element, the console logs show that the $refs of the component element are inaccessible. I think this might...
Read more >
Python File seek() Method - W3Schools
Python File seek() Method​​ The seek() method sets the current file position in a file stream. The seek() method also returns the new...
Read more >
How to use Goal Seek in Excel for What-If analysis - Ablebits
The tutorial explains how to use Goal Seek in Excel for What-If analysis: get the desired formula result by changing an input value....
Read more >
Unavailable or Problem References? What You Can Do - ALIS
Call the company where your reference used to work and ask if they have new contact details. Some companies won't give out home...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found