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.

player seekTo function not working in onReady callback?

See original GitHub issue

Describe the bug When the video is loaded I would like to start playing the video at some time not at the start of the video using the player seekto function. But for some reason it doesn’t work and always play the video at the start of video.

To Reproduce Steps to reproduce the behavior:

import React, {useCallback, useRef } from "react";
import {View } from "react-native";
import YoutubePlayer from "react-native-youtube-iframe";

export default function App() {
  const playerRef: any = useRef();


  const onPlayerReady = useCallback(() => {
    playerRef.current?.seekTo("30");
  }, []);

  return (
    <View>
      <YoutubePlayer
         ref={playerRef} 
        height={300}
        play={false}
        videoId={"DC471a9qrU4"}
        onReady={onPlayerReady}
      />
   
    </View>
  );
}

Expected behavior Video current time should be at 30 sec of video.

Smartphone (please complete the following information):

  • Device: iPhone SE 2020 & Pixel 3
  • OS: iOS 14.4.2 & Android Version 11
  • react-native-youtube-iframe 2.0.1
  • react-native-webview 11.0.0
  • Expo verison 40.0.0

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
LonelyCppcommented, Apr 12, 2021

There’s a better way to achieve this particular use-case with start in initialPlayerParams. docs

<YoutubePlayer
  ref={ref}
  play={true} 
  videoId={"vZaIZgkCcXQ"}
  initialPlayerParams={{ start: 30 }} // start video at a timestamp
/>
0reactions
davidhouse2003commented, Apr 12, 2021

Wow thanks so much for the explanation and code tip. It worked perfectly!

Read more comments on GitHub >

github_iconTop Results From Across the Web

youtube api - Player.seekTo is not a function - Stack Overflow
seekTo function fails with _player2.default.seekTo is not a function while the Player.getCurrentTime() function call works just as expected.
Read more >
SeekTo always seekto 0 #723 - cookpete/react-player - GitHub
Current Behavior When i use seekTo method on ref, the player will always go back to the begining, and the onseek callback gives...
Read more >
YouTube Player API Reference for iframe Embeds
This function loads the specified video's thumbnail and prepares the player to play the video. The player does not request the FLV until...
Read more >
Player Events - Brightcove Player Documentation
In this topic, you will learn about the various types of events associated with Brightcove Player.
Read more >
react-native-youtube-iframe-with-fs-callback - npm
A wrapper of the Youtube IFrame player API build for react native. ✓ Works seamlessly on both ios and android platforms; ✓ Does...
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