sampotts / plyr

A simple HTML5, YouTube and Vimeo player
https://plyr.io
MIT License
26.37k stars 2.92k forks source link

What is the best way to add a player dynamically #2534

Open rvrajj opened 1 year ago

rvrajj commented 1 year ago

After initializing the player as const players = Plyr.setup('.js-player'); I want to add another video dynamically, but just adding a video tag with class js-player does not initializes it as Plyr.

The actual question is : How to add a video/audio dynamically in plyr ui?

AlizerUncaged commented 1 year ago

I have the same question, basically I implemented an post scrolling in my site and videos get added whenever the user hits the bottom of the page, however Plyr doesn't seem to get applied to the newly loaded videos even if it has the player class which I passed through let player = new Plyr('.player'), is there any solutions for this?

AlizerUncaged commented 1 year ago

So finally 2 seconds of reading README I was able to make it work, I decided to put a randomized Id to each of the players being appended to the HTML and at the very end of the loop I put let player = new Plyr(document.getElementById(randomizedId));.