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.

Question: Ref.seekTo is not a function

See original GitHub issue

I am using react-player with my next.js site and am having trouble using seekTo function. It results in error saying: “playerRef.seekTo is not a function”

I tried “playerRef.current.seekTo(parseFloat(e.target.value))” as well but same error occurs

This was my code:

import { useRef } from "react";
 const ReactPlayer = dynamic(() => import("react-player"), { ssr: false });

 const Player = ({url}) => {

 const playerRef = useRef();

 const [player, setPlayer] = useState({
     playing: true,
     muted: true,
     played: 0,
     loaded: 0,
     duration: 0,
     seeking:false
   });

 const handlePlayPause = function () {
 setPlayer({ ...player, playing: !player.playing });
};

const handleMuted = () => {
   setPlayer({ ...player, muted: !player.muted });
};

const handleSeekMouseDown = (e) => {
 setPlayer({ ...player, seeking: true });
};

const handleSeekChange = (e) => {
 setPlayer({ ...player, played: parseFloat(e.target.value) });
};

const handleSeekMouseUp = (e) => {
 setPlayer({ ...player, seeking: false });
 playerRef.seekTo(parseFloat(e.target.value));
};

const handleProgress = (state) => {
 if (!player.seeking) {
   setPlayer(state);
 }
};

return (
 <div
   className={`relative justify-center content-center w-full`}
  
 >
   <ReactPlayer
     ref={playerRef}
     className="absolute rounded"
     width="100%"
     height="100%"
     url={url}
     volume={1}
     playIcon={<></>}
     playing={player.playing}
     loop={true}
     muted={player.muted}
     onProgress={handleProgress}
   ></ReactPlayer>

   <div
     className={"absolute w-full h-full"}
     onClick={handlePlayPause}
   ></div>

   <div>
     <input
       type="range"
       min={0}
       max={0.999999}
       step="any"
       value={player.played}
       onMouseDown={handleSeekMouseDown}
       onChange={handleSeekChange}
       onMouseUp={handleSeekMouseUp}
     />
   </div>
 </div>
);
};
 
export default Player;

Even when I copy paste exact code from demo(https://github.com/cookpete/react-player/blob/master/src/demo/App.js), same error shows, I’m not sure why it happens 😦

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

1reaction
pszopa-tlcommented, Nov 30, 2022

Same issue but with showPreview() method. The only thing that is under playerRef.current is a mysterious function retry().

I’m using react-player@2.11.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

youtube api - Player.seekTo is not a function - Stack Overflow
From the documentation of YouTube, the player.seekTo(seconds:Number, allowSeekAhead:Boolean) has two parameter that you need to set.
Read more >
How to use ReactPlayer with functional component? #791
I can not use ref inside function component. ... <button onClick={() => ref.current.seekTo(10)}>Seek to 00:10</button> </div> ) }.
Read more >
react-player - Bountysource
I am using react-player with my next.js site and am having trouble using seekTo function. It results in error saying: "playerRef.seekTo is not...
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 >
10 Essential Public Health Services - CSTLTS - CDC
The 10 Essential Public Health Services provide a framework to protect and promote the health of all people in all communities.
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