Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda