player seekTo function not working in onReady callback?
See original GitHub issueDescribe 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-iframe2.0.1react-native-webview11.0.0Expoverison 40.0.0
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

There’s a better way to achieve this particular use-case with
startininitialPlayerParams. docsWow thanks so much for the explanation and code tip. It worked perfectly!