cms icon indicating copy to clipboard operation
cms copied to clipboard

feature: Play/Pause Effect on the Video Player

Open mrpaaradox opened this issue 1 year ago • 4 comments

Description: Once the user hits play/pause an effect should be shown on the video player like we have in the below Screenshot/or a basic Youtube Video Player.

image image

mrpaaradox avatar Apr 08 '24 16:04 mrpaaradox

Trying this one out.

dheerajsharma1805 avatar Apr 08 '24 17:04 dheerajsharma1805

I think this was the logic if i am right please merge this sir

const video = document.getElementById('videoPlayer') as HTMLVideoElement; const playPauseButton = document.getElementById('playPauseButton') as HTMLButtonElement;

playPauseButton.addEventListener('click', togglePlayPause);

function togglePlayPause() { if (video.paused) { video.play(); // Add effect for play video.classList.add('playing-effect'); } else { video.pause(); // Add effect for pause video.classList.remove('playing-effect'); } } //and add some css ....

Aryam2121 avatar Apr 08 '24 18:04 Aryam2121

import React, { useEffect, useRef, FunctionComponent, useState } from 'react'; import videojs from 'video.js'; import 'video.js/dist/video-js.css';

interface VideoPlayerProps {

}

const VideoPlayer: FunctionComponent<VideoPlayerProps> = ({ /* Your props destructuring */ }) => { const videoRef = useRef<HTMLVideoElement>(null); const [playing, setPlaying] = useState(false);

useEffect(() => { const videoElement = videoRef.current; if (!videoElement) return;

const player = videojs(videoElement);

player.on('play', () => {
  setPlaying(true);
});

player.on('pause', () => {
  setPlaying(false);
});

return () => {
  player.dispose();
};

}, []);

const togglePlayPause = () => { const videoElement = videoRef.current; if (!videoElement) return;

if (videoElement.paused) {
  videoElement.play();
} else {
  videoElement.pause();
}

};

return (

<video ref={videoRef} className="video-js" /> <button onClick={togglePlayPause}> {playing ? 'Pause' : 'Play'}
); };

export default VideoPlayer;

Aryam2121 avatar Apr 08 '24 18:04 Aryam2121

Hi , is anyone working on this ??

heyhexadecimal avatar Apr 08 '24 21:04 heyhexadecimal