DEV Community

Cover image for How to Create a Video Player in React

How to Create a Video Player in React

Francisco Mendes on August 14, 2021

One of the things that interested me most recently is creating a fully customized video player. Obviously, nowadays we have services that provide w...
Collapse
 
code_rabbi profile image
Emeka Orji

Thanks @franciscomendes10866 , this helped me in a project I am working on, Thanks again

Collapse
 
carlosjara profile image
Carlos Jaramillo

I really appreciate your time in this post!, Thank you.

Collapse
 
georgewl profile image
George WL

That feels like too many useStates, and could more easily be combined into a single reducer and/or a custom hook

Collapse
 
franciscomendes10866 profile image
Francisco Mendes

Good tip, the code is definitely easier to read. Thank you! 🙌

Collapse
 
jackieli123723 profile image
Jackieli

css style not work github code ?

Collapse
 
georgewl profile image
George WL

How so do you mean?

Collapse
 
franciscomendes10866 profile image
Francisco Mendes

It is not working? In which component?

Collapse
 
beepboop profile image
Kode Creer

This isn't working in the progress bar even after pasting your code into the temple and the same libraries. Please provide a GitHub link please, it makes solving these issues easier.

Collapse
 
cristian327 profile image
David P.

Css my friend

Collapse
 
georgewl profile image
George WL

I would recommend instead of using a large state object, you instead make use of the useReducer hook, this would also simplify your handlers by bundling them into the reducer

Collapse
 
franciscomendes10866 profile image
Francisco Mendes

It's a good approach 🧐 Thanks 🙌

Collapse
 
nikoteresin profile image
spooner.eth

hi, somehow the video is not showing on mobile safari / chrome. anyone who had the same problem and a solution?

Collapse
 
tinapc profile image
Hung Nguyen

Thanks a lot bro! This article is really good and I learned more thing from it.

Collapse
 
franciscomendes10866 profile image
Francisco Mendes

Thank you very much! I am happy to know! 💪

Collapse
 
cyberfolks profile image
M Ibrahim Hayat

i want to add full Screen button is there any solution for full screen?

Collapse
 
nosovandrew profile image
Andrew Nosov

Hi! You can make it by adding to useVideoPlayer hook following func:

const toggleFullscreen = () => {
    if (videoElement.current) {
            videoElement.current.requestFullscreen();
    }
}
Enter fullscreen mode Exit fullscreen mode

Then you can run this func by clicking on the desired icon.

Collapse
 
hypelab profile image
hype-lab • Edited

There seems to be inconsistency between the video element and the input type range element. Exactly like in the article code when triggering handleVideoProgress, the time calculated for progress seems completely inconsistent (event.target.value is always close to zero),
also player css doesn't seem to work very well with elements:

Image description

"Pause" text and "unmute" text instead of buttons because seems there isn't class for them in the sample player.css.
(even if the graphics don't bother me that much at the moment)

Collapse
 
hypelab profile image
hype-lab

Ok it's my fault, I was too superficial.
In my case it was all about CSS.
The problem lies in having to deal with the pseudo elements (both webkit and moz and ms), to be managed even when Fullscreen API is requested (always managing the different browsers)

Collapse
 
bvince77 profile image
bvince77 • Edited

Great article. Very easy to understand and follow

Collapse
 
franciscomendes10866 profile image
Francisco Mendes

Thank you very much for your feedback! 👊

Collapse
 
sajaddp profile image
Sajad DP

It,s great! thanks man.

Collapse
 
franciscomendes10866 profile image
Francisco Mendes

Thanks for the feedback! 👊

Collapse
 
shashwattopre profile image
Shashwat7725

It is not getting deployed in netlify

Collapse
 
dmtri profile image
dmt • Edited

Great article, but this approach is bad for performance though since the App component (and the video element) keep getting re-rendered on every video frame

Collapse
 
bhaveshkumar6 profile image
Bhavesh Kumar Agrawal

I want to add Zoom In and Zoom out button is there any solution for it?

Collapse
 
rachelcorawood profile image
Cora

hmmm, the toggleMute and handleVideoSpeed are coming up undefined which is weird. I followed step by step. Any suggestions of things to check?

Collapse
 
mooen profile image
Moeen35245

How to play a youtube video by its link in this player