├── .gitignore ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.js ├── Components │ ├── Control.css │ └── Control.jsx ├── format.js ├── index.css └── index.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `yarn test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `yarn build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `yarn eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `yarn build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-video-player", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@material-ui/core": "^4.12.4", 7 | "@material-ui/icons": "^4.11.3", 8 | "@testing-library/jest-dom": "^5.14.1", 9 | "@testing-library/react": "^13.0.0", 10 | "@testing-library/user-event": "^13.2.1", 11 | "react": "^18.2.0", 12 | "react-dom": "^18.2.0", 13 | "react-player": "2.10.1", 14 | "react-scripts": "5.0.1", 15 | "web-vitals": "^2.1.0" 16 | }, 17 | "scripts": { 18 | "start": "react-scripts start", 19 | "build": "react-scripts build", 20 | "test": "react-scripts test", 21 | "eject": "react-scripts eject" 22 | }, 23 | "eslintConfig": { 24 | "extends": [ 25 | "react-app", 26 | "react-app/jest" 27 | ] 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wesley-codes/React-player/4412e8163a0b2383e58b698a059baafba2557498/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wesley-codes/React-player/4412e8163a0b2383e58b698a059baafba2557498/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wesley-codes/React-player/4412e8163a0b2383e58b698a059baafba2557498/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | .video_container { 5 | display: flex; 6 | flex-direction: column; 7 | justify-content: center; 8 | align-items: center; 9 | width: 100%; 10 | } 11 | 12 | .player__wrapper { 13 | position: relative; 14 | } 15 | 16 | .player { 17 | border: 2px solid #7b2cbf; 18 | object-fit: cover; 19 | padding: 0; 20 | margin: 0; 21 | } 22 | 23 | h2 { 24 | color: #7b2cbf; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import ReactPlayer from "react-player"; 3 | import { Container } from "@material-ui/core"; 4 | import Control from "./Components/Control"; 5 | import { useState, useRef } from "react"; 6 | import { formatTime } from "./format"; 7 | 8 | let count = 0; 9 | function App() { 10 | const videoPlayerRef = useRef(null); 11 | const controlRef = useRef(null); 12 | 13 | const [videoState, setVideoState] = useState({ 14 | playing: true, 15 | muted: false, 16 | volume: 0.5, 17 | playbackRate: 1.0, 18 | played: 0, 19 | seeking: false, 20 | buffer: true, 21 | }); 22 | 23 | //Destructuring the properties from the videoState 24 | const { playing, muted, volume, playbackRate, played, seeking, buffer } = 25 | videoState; 26 | 27 | const currentTime = videoPlayerRef.current 28 | ? videoPlayerRef.current.getCurrentTime() 29 | : "00:00"; 30 | const duration = videoPlayerRef.current 31 | ? videoPlayerRef.current.getDuration() 32 | : "00:00"; 33 | 34 | const formatCurrentTime = formatTime(currentTime); 35 | const formatDuration = formatTime(duration); 36 | 37 | const playPauseHandler = () => { 38 | //plays and pause the video (toggling) 39 | setVideoState({ ...videoState, playing: !videoState.playing }); 40 | }; 41 | 42 | const rewindHandler = () => { 43 | //Rewinds the video player reducing 5 44 | videoPlayerRef.current.seekTo(videoPlayerRef.current.getCurrentTime() - 5); 45 | }; 46 | 47 | const handleFastFoward = () => { 48 | //FastFowards the video player by adding 10 49 | videoPlayerRef.current.seekTo(videoPlayerRef.current.getCurrentTime() + 10); 50 | }; 51 | 52 | //console.log("========", (controlRef.current.style.visibility = "false")); 53 | const progressHandler = (state) => { 54 | if (count > 3) { 55 | console.log("close"); 56 | controlRef.current.style.visibility = "hidden"; // toggling player control container 57 | } else if (controlRef.current.style.visibility === "visible") { 58 | count += 1; 59 | } 60 | 61 | if (!seeking) { 62 | setVideoState({ ...videoState, ...state }); 63 | } 64 | }; 65 | 66 | const seekHandler = (e, value) => { 67 | setVideoState({ ...videoState, played: parseFloat(value / 100) }); 68 | videoPlayerRef.current.seekTo(parseFloat(value / 100)); 69 | }; 70 | 71 | const seekMouseUpHandler = (e, value) => { 72 | console.log(value); 73 | 74 | setVideoState({ ...videoState, seeking: false }); 75 | videoPlayerRef.current.seekTo(value / 100); 76 | }; 77 | 78 | const volumeChangeHandler = (e, value) => { 79 | const newVolume = parseFloat(value) / 100; 80 | 81 | setVideoState({ 82 | ...videoState, 83 | volume: newVolume, 84 | muted: Number(newVolume) === 0 ? true : false, // volume === 0 then muted 85 | }); 86 | }; 87 | 88 | const volumeSeekUpHandler = (e, value) => { 89 | const newVolume = parseFloat(value) / 100; 90 | 91 | setVideoState({ 92 | ...videoState, 93 | volume: newVolume, 94 | muted: newVolume === 0 ? true : false, 95 | }); 96 | }; 97 | 98 | const muteHandler = () => { 99 | //Mutes the video player 100 | setVideoState({ ...videoState, muted: !videoState.muted }); 101 | }; 102 | 103 | const onSeekMouseDownHandler = (e) => { 104 | setVideoState({ ...videoState, seeking: true }); 105 | }; 106 | 107 | const mouseMoveHandler = () => { 108 | controlRef.current.style.visibility = "visible"; 109 | count = 0; 110 | }; 111 | 112 | const bufferStartHandler = () => { 113 | console.log("Bufering......."); 114 | setVideoState({ ...videoState, buffer: true }); 115 | }; 116 | 117 | const bufferEndHandler = () => { 118 | console.log("buffering stoped ,,,,,,play"); 119 | setVideoState({ ...videoState, buffer: false }); 120 | }; 121 | 122 | return ( 123 |
124 |
125 |

React player

126 |
127 | 128 |
129 | 142 | 143 | {buffer &&

Loading

} 144 | 145 | 164 |
165 |
166 |
167 | ); 168 | } 169 | 170 | export default App; 171 | -------------------------------------------------------------------------------- /src/Components/Control.css: -------------------------------------------------------------------------------- 1 | .control_Container { 2 | background-color: rgba(0, 0, 0, 0.6); 3 | position: absolute; 4 | top: 0; 5 | bottom: 0; 6 | right: 0; 7 | left: 0; 8 | flex-direction: column; 9 | z-index: 1; 10 | display: flex; 11 | justify-content: space-between; 12 | } 13 | 14 | .top_container { 15 | display: flex; 16 | align-items: center; 17 | justify-content: space-between; 18 | margin: 5px 20px; 19 | } 20 | 21 | .mid__container { 22 | display: flex; 23 | justify-content: center; 24 | align-items: center; 25 | } 26 | 27 | .icon__btn { 28 | padding: 0 10px; 29 | color: #7b2cbf; 30 | } 31 | 32 | .slider__container { 33 | /* width: 100%; */ 34 | display: flex; 35 | align-items: center; 36 | padding: 0 16px; 37 | } 38 | 39 | .control__box { 40 | display: flex; 41 | align-items: center; 42 | justify-content: space-between; 43 | } 44 | 45 | .inner__controls { 46 | display: flex; 47 | padding: 10px 0; 48 | align-items: center; 49 | width: 50%; 50 | } 51 | 52 | span { 53 | color: #fff; 54 | font-size: 0.8rem; 55 | margin-left: 10px; 56 | } 57 | 58 | .second__control { 59 | display: flex; 60 | align-items: center; 61 | } 62 | -------------------------------------------------------------------------------- /src/Components/Control.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { 3 | makeStyles, 4 | Slider, 5 | withStyles, 6 | Button, 7 | Tooltip, 8 | Popover, 9 | Grid, 10 | } from "@material-ui/core"; 11 | import { 12 | FastForward, 13 | FastRewind, 14 | Pause, 15 | PlayArrow, 16 | SkipNext, 17 | VolumeUp, 18 | VolumeOff 19 | } from "@material-ui/icons"; 20 | import "./Control.css"; 21 | 22 | const useStyles = makeStyles({ 23 | volumeSlider: { 24 | width: "100px", 25 | color: "#9556CC", 26 | }, 27 | 28 | bottomIcons: { 29 | color: "#999", 30 | padding: "12px 8px", 31 | 32 | "&:hover": { 33 | color: "#fff", 34 | }, 35 | }, 36 | }); 37 | 38 | const PrettoSlider = withStyles({ 39 | root: { 40 | height: "20px", 41 | color: "#9556CC", 42 | display: "flex", 43 | justifyContent: "center", 44 | alignItems: "center", 45 | }, 46 | thumb: { 47 | height: 20, 48 | width: 20, 49 | backgroundColor: "#9556CC", 50 | border: "2px solid currentColor", 51 | marginTop: -3, 52 | marginLeft: -12, 53 | "&:focus, &:hover, &$active": { 54 | boxShadow: "inherit", 55 | }, 56 | }, 57 | active: {}, 58 | valueLabel: { 59 | left: "calc(-50% + 4px)", 60 | }, 61 | track: { 62 | height: 5, 63 | borderRadius: 4, 64 | width: "100%", 65 | }, 66 | rail: { 67 | height: 5, 68 | borderRadius: 4, 69 | }, 70 | })(Slider); 71 | 72 | const Control = ({ 73 | onPlayPause, 74 | playing, 75 | onRewind, 76 | onForward, 77 | played, 78 | onSeek, 79 | onSeekMouseUp, 80 | onVolumeChangeHandler, 81 | onVolumeSeekUp, 82 | volume, 83 | mute, 84 | onMute, 85 | duration, 86 | currentTime, 87 | onMouseSeekDown, 88 | controlRef 89 | }) => { 90 | const classes = useStyles(); 91 | 92 | 93 | return ( 94 |
95 |
96 |

Video PLayer

97 |
98 |
99 |
100 | 101 |
102 | 103 |
104 | {playing ? ( 105 | 106 | ) : ( 107 | 108 | )}{" "} 109 |
110 | 111 |
112 | 113 |
114 |
115 |
116 |
117 | 125 |
126 |
127 |
128 |
129 | {playing ? ( 130 | 131 | ) : ( 132 | 133 | )}{" "} 134 |
135 | 136 |
137 | 138 |
139 | 140 |
141 | {mute ? ( 142 | 143 | ) : ( 144 | 145 | )} 146 |
147 | 148 | 154 | 155 | { currentTime} : {duration} 156 |
157 | 158 |
159 |
160 |
161 | ); 162 | }; 163 | 164 | export default Control; 165 | -------------------------------------------------------------------------------- /src/format.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | export const formatTime = (time) => { 4 | //formarting duration of video 5 | if (isNaN(time)) { 6 | return "00:00"; 7 | } 8 | 9 | const date = new Date(time * 1000); 10 | const hours = date.getUTCHours(); 11 | const minutes = date.getUTCMinutes(); 12 | const seconds = date.getUTCSeconds().toString().padStart(2, "0"); 13 | if (hours) { 14 | //if video have hours 15 | return `${hours}:${minutes.toString().padStart(2, "0")} `; 16 | } else return `${minutes}:${seconds}`; 17 | }; -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | padding: 0; 9 | margin: 0; 10 | box-sizing: border-box; 11 | background: #F6F6F6; 12 | } 13 | 14 | code { 15 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 16 | monospace; 17 | } 18 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | const root = ReactDOM.createRoot(document.getElementById('root')); 7 | root.render( 8 | 9 | <> 10 | 11 | 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | --------------------------------------------------------------------------------