Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda