plyr.js example in angular 10

How to use plyr.js in Angular 10

Plyr.js is a powerful, accessible and customizable media player library that can be used in your Angular 10 projects. Here are some ways to use plyr.js in Angular 10:

Using plyr.js with Angular CLI

One way to use plyr.js in your Angular 10 project is to install it using npm and import it in your component. Here's how:


  npm install plyr --save

Once you have installed plyr, you can import it in your component like this:


  import Plyr from 'plyr';

You can now use plyr.js in your component by creating a new plyr instance and passing in the video element:


  const player = new Plyr('#video-player');

Using plyr.js with Angular Universal

If you are using Angular Universal for server-side rendering, you need to make some changes to your code to make plyr.js work. Here's how:

First, install the plyr.js package:


  npm install plyr --save

Next, you need to add the following lines of code to your app.server.module.ts file:


  import { applyPolyfills, defineCustomElements } from 'plyr/loader';

  applyPolyfills().then(() => {
    defineCustomElements(window);
  });

Finally, you need to make sure that plyr.js is loaded on the client side as well. You can do this by adding the following lines of code to your index.html file:


  <script src="https://cdn.plyr.io/3.6.4/plyr.polyfilled.min.js"></script>

You can now use plyr.js in your Angular 10 project with server-side rendering.

Customizing plyr.js

Plyr.js is highly customizable, and you can change its appearance and functionality to suit your needs. Here are some customization options:

  • Skin: You can change the skin of plyr.js by adding a CSS file. You can find pre-made skins on the plyr.js website or create your own.
  • Controls: You can customize the controls of plyr.js by adding or removing buttons. You can also change the position of the controls.
  • Settings: You can change the settings of plyr.js, such as the loop option, autoplay option, and more.

To customize plyr.js, you need to add the necessary CSS and JavaScript code to your project. You can find more information on how to customize plyr.js on the plyr.js website.

In conclusion, using plyr.js in your Angular 10 project is a great way to add a customizable and accessible media player to your website. Whether you are using Angular CLI or Angular Universal, you can easily integrate plyr.js into your project and customize it to suit your needs.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe