### Clone and Run Demo Locally Source: https://github.com/cookpete/react-player/blob/master/CONTRIBUTING.md Clone the repository, install dependencies, start the development server, and open the demo in your browser. ```bash git clone https://github.com/CookPete/react-player.git cd react-player npm install # or yarn npm start open http://localhost:3000 ``` -------------------------------- ### Install ReactPlayer Source: https://github.com/cookpete/react-player/blob/master/README.md Install ReactPlayer using npm or yarn. This is the first step to integrating the component into your React project. ```bash npm install react-player # or yarn add react-player ``` -------------------------------- ### Basic ReactPlayer Usage Source: https://github.com/cookpete/react-player/blob/master/README.md Import ReactPlayer and use it by providing a media URL to the 'src' prop. This example demonstrates rendering a YouTube player. ```jsx import React from 'react' import ReactPlayer from 'react-player' // Render a YouTube video player ``` -------------------------------- ### Create a Responsive Player Source: https://github.com/cookpete/react-player/blob/master/README.md Achieve a responsive player by setting width to '100%', height to 'auto', and specifying an `aspectRatio`. ```js ``` -------------------------------- ### Run Tests with Karma, Mocha, and Chai Source: https://github.com/cookpete/react-player/blob/master/CONTRIBUTING.md Execute the test suite in the browser using Karma, Mocha, and Chai. Add new tests for any new functionality. ```bash npm test ``` -------------------------------- ### Configure YouTube Player Options Source: https://github.com/cookpete/react-player/blob/master/README.md Use the `config` prop to pass specific settings to the YouTube player. Refer to the YouTube Player API for available parameters. ```jsx ``` -------------------------------- ### Lint Code with StandardJS Source: https://github.com/cookpete/react-player/blob/master/CONTRIBUTING.md Run the linting script to check code style according to the project's standard configuration. Fix any reported issues. ```bash npm run lint ``` -------------------------------- ### Enable Light Player with Thumbnail Source: https://github.com/cookpete/react-player/blob/master/README.md Use the `light` prop to display a thumbnail and play icon, deferring full player load until interaction. Supports image URLs or components for custom thumbnails. ```jsx } /> ``` -------------------------------- ### Enable Native Player Controls Source: https://github.com/cookpete/react-player/blob/master/README.md Use the `controls` prop to enable native player controls. Appearance varies by player type. ```jsx ``` -------------------------------- ### Add Custom Player Implementation Source: https://github.com/cookpete/react-player/blob/master/README.md Integrate your own player compatible with ReactPlayer's architecture using `ReactPlayer.addCustomPlayer`. ```javascript import YourOwnPlayer from './somewhere'; ReactPlayer.addCustomPlayer(YourOwnPlayer); ``` -------------------------------- ### Integrate Media Chrome for Custom Controls Source: https://github.com/cookpete/react-player/blob/master/README.md Combine React Player with Media Chrome components for a customizable UI. Ensure `controls` is false on ReactPlayer. ```tsx import ReactPlayer from "react-player"; import { MediaController, MediaControlBar, MediaTimeRange, MediaTimeDisplay, MediaVolumeRange, MediaPlaybackRateButton, MediaPlayButton, MediaSeekBackwardButton, MediaSeekForwardButton, MediaMuteButton, MediaFullscreenButton, } from "media-chrome/react"; export default function Player() { return ( ); } ``` -------------------------------- ### Import Lazy Player in React Player v2.2 Source: https://github.com/cookpete/react-player/blob/master/MIGRATING.md Use 'react-player/lazy' for lazy loading players to reduce main bundle size. Requires React 16.6 or later. ```jsx import ReactPlayer from 'react-player' // After import ReactPlayer from 'react-player/lazy' ``` -------------------------------- ### Handle Player Ready State in ReactPlayer Source: https://github.com/cookpete/react-player/blob/master/MIGRATING.md Before v2.0, refs were used to access the player instance. In v2.0, `onReady` is invoked with the player instance, allowing direct method calls. This is useful for accessing internal player methods like `getInternalPlayer`. ```jsx class Player extends Component { ref = player => { this.player = player // Store a player that may not be ready for methods this.player.getInternalPlayer() // Returns null if player is not ready } handleReady = () => { this.player.getInternalPlayer() // Internal player now ready } render () { return ( ) } } ``` ```jsx class Player extends Component { handleReady = player => { this.player = player // Store a player that is ready for methods this.player.getInternalPlayer() // Internal player now ready } render () { return ( ) } } ``` -------------------------------- ### ReactPlayer Static Methods Source: https://github.com/cookpete/react-player/blob/master/README.md Static methods available on the ReactPlayer component. ```APIDOC ## ReactPlayer Static Methods ### Description Static methods available on the ReactPlayer component. ### Methods - `ReactPlayer.canPlay(src)`: Determine if a URL can be played. This does *not* detect media that is unplayable due to privacy settings, streaming permissions, etc. In that case, the `onError` prop will be invoked after attempting to play. Any URL that does not match any patterns will fall back to a native HTML5 media player. - `ReactPlayer.addCustomPlayer(CustomPlayer)`: Add a custom player. See [Adding custom players](#adding-custom-players). - `ReactPlayer.removeCustomPlayers()`: Remove any players that have been added using `addCustomPlayer()`. ``` -------------------------------- ### Multiple Sources and Tracks in ReactPlayer Source: https://github.com/cookpete/react-player/blob/master/README.md Use multiple `` and `` elements within ReactPlayer to manage different media sources and subtitle tracks, similar to native HTML video/audio elements. This functionality is available from v3 onwards. ```jsx ``` -------------------------------- ### ReactPlayer Props Source: https://github.com/cookpete/react-player/blob/master/README.md Props to configure the behavior and appearance of the React Player component. ```APIDOC ## ReactPlayer Props ### Description Props to configure the behavior and appearance of the React Player component. ### Props - `src` (string) - The url of a video or song to play. Default: `undefined` - `playing` (boolean) - Set to `true` or `false` to play or pause the media. Default: `undefined` - `preload` (string) - Applies the `preload` attribute where supported. Default: `undefined` - `playsInline` (boolean) - Applies the `playsInline` attribute where supported. Default: `false` - `disableRemotePlayback` (boolean) - Applies the `disableRemotePlayback` attribute where supported. Default: `false` - `crossOrigin` (string) - Applies the `crossOrigin` attribute where supported. Default: `undefined` - `loop` (boolean) - Set to `true` or `false` to loop the media. Default: `false` - `controls` (boolean) - Set to `true` or `false` to display native player controls. For Vimeo videos, hiding controls must be enabled by the video owner. Default: `false` - `volume` (number) - Set the volume of the player, between `0` and `1`. `null` uses default volume on all players. Default: `null` - `muted` (boolean) - Mutes the player. Default: `false` - `playbackRate` (number) - Set the playback rate of the player. Only supported by YouTube, Wistia, and file paths. Default: `1` - `pip` (boolean) - Set to `true` or `false` to enable or disable picture-in-picture mode. Only available when playing file URLs in certain browsers. Default: `false` - `width` (string) - Set the width of the player. Default: `320px` - `height` (string) - Set the height of the player. Default: `180px` - `style` (object) - Add inline styles to the root element. Default: `{}` - `light` (boolean|string) - Set to `true` to show just the video thumbnail, which loads the full player on click. Pass in an image URL to override the preview image. Default: `false` - `fallback` (element|component) - Element or component to use as a fallback if you are using lazy loading. Default: `null` - `wrapper` (element|component) - Element or component to use as the container element. Default: `null` - `playIcon` (element|component) - Element or component to use as the play icon in light mode. - `previewTabIndex` (number) - Set the tab index to be used on light mode. Default: `0` ### Callback Props Callback props take a function that gets fired on various player events: - `onClickPreview` - Called when user clicks the `light` mode preview. - `onReady` - Called when media is loaded and ready to play. If `playing` is set to `true`, media will play immediately. - `onStart` - Called when media starts playing. - `onPlay` - Called when the `playing` prop is set to true. - `onPlaying` - Called when media actually starts playing. - `onProgress` - Called when media data is loaded. - `onTimeUpdate` - Called when the media's current time changes. - `onDurationChange` - Callback containing duration of the media, in seconds. - `onPause` - Called when media is paused. - `onWaiting` - Called when media is buffering and waiting for more data. - `onSeeking` - Called when media is seeking. - `onSeeked` - Called when media has finished seeking. - `onRateChange` - Called when playback rate of the player changed. Only supported by YouTube, Vimeo, Wistia, and file paths. - `onEnded` - Called when media finishes playing. Does not fire when `loop` is set to `true`. - `onError` - Called when an error occurs whilst attempting to play media. - `onEnterPictureInPicture` - Called when entering picture-in-picture mode. - `onLeavePictureInPicture` - Called when leaving picture-in-picture mode. ### Config Prop There is a single `config` prop to override settings for each type of player: ```jsx ``` Settings for each player live under different keys: - `youtube`: https://developers.google.com/youtube/player_parameters#Parameters - `vimeo`: https://developer.vimeo.com/player/sdk/embed - `hls`: https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning ``` -------------------------------- ### Update Config Prop for React Player Source: https://github.com/cookpete/react-player/blob/master/MIGRATING.md Deprecated config props have been removed. Use the 'config' prop with player-specific options nested inside. ```jsx // Before // After ``` ```jsx // Before // After ``` -------------------------------- ### Override Player SDK Version Source: https://github.com/cookpete/react-player/blob/master/README.md Specify a custom version for a player SDK, like `hls.js`, by adding a `resolutions` field to your `package.json`. ```json { "resolutions": { "hls.js": "1.6.2" } } ``` -------------------------------- ### Import Single Player in React Player v2.2 Source: https://github.com/cookpete/react-player/blob/master/MIGRATING.md The location for importing single players has changed in v2.2. This is not available in v2.0 and v2.1. ```jsx // Before import ReactPlayer from 'react-player/lib/players/YouTube' // After import ReactPlayer from 'react-player/youtube' ``` -------------------------------- ### Remove All Custom Players Source: https://github.com/cookpete/react-player/blob/master/README.md Clear all previously added custom players by calling `ReactPlayer.removeCustomPlayers`. ```javascript ReactPlayer.removeCustomPlayers(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.