import React from 'react';
import ReactPlayer from 'react-player';
const VideoPlayer = ({ url }) => {
return (
);
};
export default VideoPlayer;
/*
** Instructions for using this component: **
1. **Install `react-player`:**
If you haven't already, install the `react-player` library:
`npm install react-player`
or
`yarn add react-player`
2. **Import the component:**
In the React component where you want to use the video player, import it:
`import VideoPlayer from './VideoPlayer';`
(Adjust the path `./VideoPlayer` if your file structure is different).
3. **Use the component:**
Render the `VideoPlayer` component and pass the `url` prop with the video source.
**Example:**
```jsx
import React from 'react';
import VideoPlayer from './VideoPlayer'; // Adjust path as needed
function App() {
const youtubeUrl = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
const vimeoUrl = 'https://vimeo.com/243676839';
const localMp4Url = '/videos/my-local-video.mp4'; // Make sure this path is accessible in your public folder
return (
My Video Showcase
YouTube Video
Vimeo Video
Local MP4 Video
{/* For local files, ensure they are in the `public` folder or correctly imported/served */ }
{/* If using a build system like Create React App, put local videos in `public` and reference them from root */}
//
//
// );
// }
// export default App;
```
4. **Styling (Optional but Recommended):**
The component uses a `player-wrapper` div. You can add CSS to this class to control the aspect ratio and ensure it scales correctly. A common approach for responsive video players is to use padding-bottom trick for aspect ratio.
**Example CSS (e.g., in `App.css` or a dedicated CSS file):**
```css
.player-wrapper {
position: relative;
padding-top: 56.25%; /* Player ratio: 100 / (16 / 9) */
/* For 4:3 aspect ratio, use padding-top: 75%; */
}
.react-player {
position: absolute;
top: 0;
left: 0;
}
```
Without this styling, the `width="100%"` and `height="100%"` on `ReactPlayer` might not behave as expected within a flex container or other layouts, potentially causing the video to appear stretched or with incorrect dimensions. The `player-wrapper` with `padding-top` helps establish the correct aspect ratio for the video container.
**Supported URLs:**
`react-player` supports a wide range of video URLs, including:
* YouTube
* Vimeo
* Facebook
* Twitch
* SoundCloud
* Wistia
* DailyMotion
* Vidyard
* Streamable
* Wistia
* Files (MP4, WebM, OGG, etc.)
* And more...
Just pass the direct URL to the `url` prop, and `react-player` will handle the embedding.
*/