Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

plyr-react

chintan978.7kMIT5.3.0TypeScript support: included

A simple HTML5, YouTube and Vimeo player for react using plyr

react, plyr, video, vimeo, youtube, accessibility, javascript, player, media

readme

Plyr React

plyr-react logo

A responsive media player that is simple, easy to use, and customizable for video, audio, YouTube, and Vimeo.
tree-shakeable side-effect free

License Code quality Build Size Version Downloads

You can see a live demo here.

Make sure to select the version for the plyr-react in the dependencies.

Installation

# NPM
npm install plyr-react

# Yarn
yarn add plyr-react

Usage

Ready to use <Plyr /> component

The simplest form of react integration with the plyr is to use the <Plyr /> component, it is best for the static videos.

import Plyr from "plyr-react"
import "plyr-react/plyr.css"

const plyrProps = {
  source: undefined, // https://github.com/sampotts/plyr#the-source-setter
  options: undefined, // https://github.com/sampotts/plyr#options
  // Direct props for inner video tag (mdn.io/video)
}

function MyPlyrVideo() {
  return <Plyr {...plyrProps} />
}
<summary>Old version 4 plyr-react</summary> - The path for an import of css styles has been changed in version 5, if you are using the version 4, apply following change in the above code
- import "plyr-react/plyr.css"
+ import "plyr-react/dist/plyr.css"

Ready to use usePlyr hook

If you need the full control over all if possible integration one can imagine, usePlyr is your hook. Here is a simple and exact Plyr component made with the usePlyr hook. Are curios about how it works follow this thread and this proposal.

const Plyr = React.forwardRef((props, ref) => {
  const { source, options = null, ...rest } = props
  const raptorRef = usePlyr(ref, {
    source,
    options,
  })
  return <video ref={raptorRef} className="plyr-react plyr" {...rest} />
})

Accessing the plyr instance using refs

// Function base component
const MyComponent = () => {
  const ref = useRef()

  useEffect(() => {
    console.log("internal plyr instance:", ref.current.plyr)
  })

  return <Plyr ref={ref} />
}

// Class base component
class MyComponent extends Component {
  constructor(props) {
    super(props)
    this.player = createRef()
  }

  componentDidMount() {
    console.log("internal plyr instance", this.player.current.plyr)
  }

  render() {
    return <Plyr ref={(player) => (this.player.current = player)} />
  }
}

API:

Currently the exported APIs contains a latest instance of plyr.
In other words, the passing ref will have access to the player in the structure shown below.

return <Plyr ref={ref} />

// ref can get access to latest plyr instance with `ref.current.plyr`
ref = { current: { plyr } }

// so you can make your player fullscreen 🎉
ref.current.plyr.fullscreen.enter()

Example

You can fork these examples

Javascript example: stackblitz example (js)

Typescript example: codesandbox example (ts)

Basic HLS integration Codesandbox

Check out the examples directory for the useHls integration guide.

<video
  ref={usePlyr(ref, {
    ...useHls(hlsSource, options),
    source,
  })}
  className="plyr-react plyr"
/>

Demo: https://react-fpmwns.stackblitz.io

Nightly version of plyr-react:

Contribute

We are open to all new contribution, feel free to read CONTRIBUTING and CODE OF CONDUCT section, make new issue to discuss about the problem Gitter, and improve/fix/enhance the source code with your PRs. There is a ready to code Gitpod, you can jump into it from Gitpod Ready-to-Code

Support

If you like the project and want to support my work, give star ⭐ or fork it. Featured on Openbase

Thanks

  • @realamirhe For provide help for integrate to react-aptor.
  • @iwatakeshi For provide help for convert to typescript.

changelog

Changelog

v.5.0.2 (2022-05-25)

  • Fix build issues.

v.5.0.0 (2022-05-25)

  • Add UMD and SystemJS builds for CDN.

    So you can use it in single spa for example.

<script type="systemjs-importmap">
  {
    "imports": {
      "single-spa": "https://cdn.jsdelivr.net/npm/single-spa@5.9.0/lib/system/single-spa.min.js",
      "react": "https://unpkg.com/browse/react@17.0.2/umd/react.production.min.js",
      "react-dom": "https://unpkg.com/browse/react-dom@17.0.2/umd/react-dom.production.min.js",
      "plyr-react": "https://unpkg.com/plyr-react@5.0.0/umd/index.production.js"
    }
  }
</script>
  • The path for an import of css styles has been changed.
- import "plyr-react/dist/plyr.css"
+ import "plyr-react/plyr.css"
  • Optimize the core buld process and reduced the build time up to 10 seconds
  • Remove redundant stuff from the released plyr-react's package.json so there will be no underised side efffect

v4.0.0 (2022-05-02)

  • Implement usePlyr Hook and make the customization more easier
  • Integrate custom useHLS Hook make the seamless HLS integration possible.

v3.0.5 (2020-10-07)

Full Changelog

Closed issues:

  • Using ref-property #339

Merged pull requests:

v3.0.4 (2020-10-05)

Full Changelog

Merged pull requests:

v3.0.3 (2020-10-02)

Full Changelog

v3.0.2 (2020-10-01)

Full Changelog

Merged pull requests:

v3.0.1 (2020-09-30)

Full Changelog

Closed issues:

  • Convert to Typescript to aid intellisence and provide type support #308
  • Convert project to TypeScript #261
  • Typescript support #201

Merged pull requests:

v3.0.0 (2020-09-25)

Full Changelog

Security fixes:

Closed issues:

  • Could you add API to re-render the component if passing new props like sources to component? #215
  • React Player Project #212
  • Unsafe attempt to load URLDomains, protocols and ports must match. #183
  • Add npm package install instructions on README #136
  • How to run the methods like play, pause, etc.? #128

Merged pull requests:

v2.2.0 (2020-01-18)

Full Changelog

Closed issues:

  • Update Docs #65
  • Dependabot couldn't find a package.json for this project #56

Merged pull requests:

v2.0.1 (2020-01-17)

Full Changelog

v2.0.0 (2020-01-16)

Full Changelog

Merged pull requests:

* This Changelog was automatically generated by [githubchangelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)_