React-native-youtube: seekTo method is undefined

Created on 25 Mar 2017  路  9Comments  路  Source: davidohayon669/react-native-youtube

I want to be able to set the time but for some reason I do not get access to the seekTo method. Printing the reference shows the following:
image

And making a reference to it in code via this.refs.youtubePlayer.seekTo() (I do null check). I get the following error:

image

My youtube.android.js file is up to date and has the same 3 references to the seekTo method as does the github so I'm not sure what I'm doing wrong here. Anyone else have any input? I am new to react-native so maybe I'm making a reference to the seekTo method wrong here?

Most helpful comment

@iDams Perfect, that helped a lot thanks. I was attempting to get the video to start at a particular time and was using the onReady event to seek forward but it wasn't actually playing when onReady is called. Instead, I used onChangeState when the state equals started. Just thought I should leave this here in case anyone else gets stuck trying to do something similar

All 9 comments

This method is implemented on both platforms on the v1 branch

Having the same issue. But the error is Cannot read property 'seekTo' of undefined which means that the ref youtubePlayer is not defined.

I see this in the youtube.android.js:

seekTo(seconds){
    this.refs.youtubePlayer.seekTo(parseInt(seconds, 10));
  }

But there is not ref set anywhere?

Having the same issue, only on android works perfectly on iOS

Using v1 branch fixed it for me

@iDams using v1 branch, not getting the error but seekTo does nothing

Is your video playing when you're trying to seekTo? If it's on paused/stopped, the video will not start with seekTo.

If the player is paused or stopped when this function is called, the player will remain remain in the same state, but will start the video at the sought-to position when playback resumes.

https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayer#seekToMillis(int)

@iDams Perfect, that helped a lot thanks. I was attempting to get the video to start at a particular time and was using the onReady event to seek forward but it wasn't actually playing when onReady is called. Instead, I used onChangeState when the state equals started. Just thought I should leave this here in case anyone else gets stuck trying to do something similar

I had to stop working on this project so I couldn't try test things further. I still seem to not be able to make seekTo work with the v1 branch, I updated and I see the following in my android.js file:

seekTo(seconds) {
    UIManager.dispatchViewManagerCommand(
      ReactNative.findNodeHandle(this._nativeComponentRef),
      UIManager.ReactYouTube.Commands.seekTo,
      [parseInt(seconds, 10)],
    );
  }

My reference no longer throws "Cannot read property seekTo" with the v1 branch, but it still doesn't do anything for me whilst playing the video. I can't seem to find seekTo in the refs list either. (I trace when the state changes to playing just to be extra sure)

Update:

It seems like setting controls=2 means that I can't use the seekTo method! This is really awkward, is this due to the youtube plugin or native android? I don't want to provide the full access to the control scheme on the player itself if at all possible

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthiasleitner picture matthiasleitner  路  5Comments

jokopurnomoa picture jokopurnomoa  路  5Comments

savioseb picture savioseb  路  4Comments

berdof picture berdof  路  4Comments

manjeet-dobble picture manjeet-dobble  路  5Comments