Search code examples
javascripthtmlcssplyr.js

How can I add two videos in PlyrJS


I encountered a problem with plyr.io library, I don't know the problem from me or from the same library,

the problem When adding more than one video to the page

what do I want? I would like to add two videos, but when I add two videos, one of them is formatting and the other is not, is there a solution to the problem?

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.6.4/plyr.css" integrity="sha512-bMLolM8mWTXYQSC2gQOLyDdkmodSAbbRFbDoISUCRS7mFJrP3fBHJo3YR8+2Yy9n7+iVGawVpCe6KVd/E5+TNA==" crossorigin="anonymous" />
<style>
    .mydiv {
        width: 500px;
        height: 200px;
        margin-top: 200px
    }
</style>
<div class="mydiv">
    <div class="plyr__video-embed" id="player">
        <iframe src="https://www.youtube.com/embed/K1QICrgxTjA&t" allowfullscreen allowtransparency allow="autoplay"></iframe>
    </div>
</div>

<div class="mydiv">
    <div class="plyr__video-embed" id="player">
        <iframe src="https://www.youtube.com/embed/K1QICrgxTjA&t" allowfullscreen allowtransparency allow="autoplay"></iframe>
    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.6.4/plyr.js" integrity="sha512-M/AUlH5tMMuhvt9trN4rXBjsXq9HrOUmtblZHhesbx97sGycEnXX/ws1W7yyrF8zEjotdNhYNfHOd3WMu96eKA==" crossorigin="anonymous"></script>

<script>
    const player = new Plyr('#player', {
        title: 'Example Title',
        quality: {
            default: 576,
            options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240]
        }

    });
</script>

Solution

  • In PlyrJS you need to add it for every video like:

    <div class="mydiv">
        <div class="plyr__video-embed" id="player1">
            <iframe src="https://www.youtube.com/embed/K1QICrgxTjA&t" allowfullscreen allowtransparency allow="autoplay"></iframe>
        </div>
    </div>
    
    <div class="mydiv">
        <div class="plyr__video-embed" id="player2">
            <iframe src="https://www.youtube.com/embed/K1QICrgxTjA&t" allowfullscreen allowtransparency allow="autoplay"></iframe>
        </div>
    </div>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.6.4/plyr.js" integrity="sha512-M/AUlH5tMMuhvt9trN4rXBjsXq9HrOUmtblZHhesbx97sGycEnXX/ws1W7yyrF8zEjotdNhYNfHOd3WMu96eKA==" crossorigin="anonymous"></script>
    
    <script>
        const player1 = new Plyr('#player1', {
            title: 'Example Title',
            quality: {
                default: 576,
                options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240]
            }
    
        });
    
        const player2 = new Plyr('#player2', {
            title: 'Example Title',
            quality: {
                default: 576,
                options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240]
            }
    
        });
    </script>