Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seekTo messes up playerRef and causing video keep playing #273

Open
bayramn opened this issue Oct 27, 2022 · 1 comment
Open

seekTo messes up playerRef and causing video keep playing #273

bayramn opened this issue Oct 27, 2022 · 1 comment

Comments

@bayramn
Copy link

bayramn commented Oct 27, 2022

Describe the bug
Calling seekTo while video is playing messes the playerRef and video keep playing regardless of being stopped. It took few hours to figure out this exact point of issue, but it only happens when you seekTo without stopping video while playing. If you stop the video and seekTo and play, everything fine. So for workaround: I stop the video before calling seekTo and play video right after done seeking, works fine and doesn't slow the video down, but it's bit weird.

To Reproduce
Steps to reproduce the behavior:

  const playerRef = useRef();

<YoutubePlayer
    initialPlayerParams={{
      start: video && video.timestamp,
      //  controls: false
    }}
    playbackRate={videoSpeed}
    ref={playerRef}
    height={250}
    videoId={videoId}
    //play={true}
    play={videoPlaying}
    onChangeState={(state) => {
      handlePlayerStateChange(state);
    }}
    webViewProps={{ androidLayerType: "software" }}
  />

const forward = async () => {
  try {
    const currentTime = await playerRef.current.getCurrentTime();
    //console.log(await playerRef.current);
    await playerRef.current.seekTo(currentTime + 15, true);
  } catch (err) {
    console.log(err);
  }
};

Expected behavior
When seekTo called while video is playing, it shouldn't mess the playerRef and it should stop when stopped.

Smartphone (please complete the following information):

  • Device: iPhone 12 Pro Max
  • OS + version: iOS 16
  • "react-native-youtube-iframe": "^2.2.2"
  • "react-native-webview": "11.23.0"
  • "expo": "^46.0.14",

Additional context
Workaround:

const forward = async () => {
  setVideoPlaying(false);
  try {
    const currentTime = await playerRef.current.getCurrentTime();
    //console.log(await playerRef.current);
    await playerRef.current.seekTo(currentTime + 15, true);
    setVideoPlaying(true);
  } catch (err) {
    console.log(err);
  }
};
@darias08
Copy link

Could you please show your full code? I am confused as to where the forward function is being used in your youtube component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@bayramn @darias08 and others