Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
Cannot set properties of undefined (setting 'player') ReactPlayer

I keep trying to use the seekTo() method on the ReactPlayer but it keeps telling me this is undefined.

function VideoPlayer({
  endVideo,
  timePlayed,
  controls,
  playing,
  videoDuration
}) {
  return (
    <div className="video-player">
      <ReactPlayer
        ref={(player) => {
          this.player = player;
        }}
        url="https://res.cloudinary.com/amarachi-2812/video/upload/v1630370229/videoplayback_1_pr2hzi.mp4"
        playing={playing}
        // playing={true}
        controls={controls}
        onStart={() => this.player.seekTo(timePlayed)}
        onEnded={endVideo}
      />
    </div>
  );
}

ReactPlayer error

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Why are you using this in an arrow function?

Try this:

import React from "react";
import ReactPlayer from "react-player";

let player;

export const VideoPlayer = ({
  endVideo,
  timePlayed,
  controls,
  playing,
  videoDuration
}) => (
  <div className="video-player">
    <ReactPlayer
      ref={(ref) => {
        player = ref;
      }}
      url="https://res.cloudinary.com/amarachi-2812/video/upload/v1630370229/videoplayback_1_pr2hzi.mp4"
      playing={playing}
      // playing={true}
      controls={controls}
      onStart={() => player.seekTo(timePlayed)}
      onEnded={endVideo}
    />
  </div>
);

export const MemoizedVideoPlayer = React.memo(VideoPlayer);
about 4 years ago · Juan Pablo Isaza Report

0

Try, set instance with help useState hook.

Wrap the handlers in useCallback to prevent unnecessary re-render, but don't forget about their dependencies if they appear.

Do not forget to look at the repository of the libraries you are using, sometimes it helps.

Also, my advice is to read about functions in more detail.

Additionally, I made a few small changes.

  • The component is named video player. The property of "videoDuration" can be called "duration". This will be more correct and we will not lose in understanding the transferred properties.
  • Url would get from props. To point the source outside and the component was reused.
  • Renamed the "endVideo" property to "onEnded". For clarity, that is, it will be named similarly to the handler to which we transfer to the react-player

Let's start!

import React, { useState, useCallback } from "react";
import ReactPlayer from "react-player";

export const VideoPlayer = ({ url, onEnded, timePlayed, controls, playing, duration}) => {
 const [instance, setInstance] = useState(null);

 const handleStart = useCallback(() => {
     if (instance) {
         instance.seekTo(timePlayed)
     }
 }, [instance, timePlayed])

 return (
    <div className="video-player">
        <ReactPlayer
            ref={setInstance}
            url={url}
            playing={playing}
            controls={controls}
            onStart={handleStart}
            onEnded={onEnded}
        />
    </div>
)};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!