Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HeNy007/c690e519ca0e066399a896548823cbb8 to your computer and use it in GitHub Desktop.
Save HeNy007/c690e519ca0e066399a896548823cbb8 to your computer and use it in GitHub Desktop.
Custom Controls with Plyr.io Video Player
<video
controls
crossorigin
playsinline
data-poster="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg" class="js-player">
<!-- Video files -->
<source
src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4"
type="video/mp4"
size="576"
/>
<source
src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4"
type="video/mp4"
size="720"
/>
<source
src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1080p.mp4"
type="video/mp4"
size="1080"
/>
</video>
document.addEventListener('DOMContentLoaded', () => {
// Controls (as seen below) works in such a way that as soon as you explicitly define (add) one control
// to the settings, ALL default controls are removed and you have to add them back in by defining those below.
// For example, let's say you just simply wanted to add 'restart' to the control bar in addition to the default.
// Once you specify *just* the 'restart' property below, ALL of the controls (progress bar, play, speed, etc) will be removed,
// meaning that you MUST specify 'play', 'progress', 'speed' and the other default controls to see them again.
const controls = [
'play-large', // The large play button in the center
'restart', // Restart playback
'rewind', // Rewind by the seek time (default 10 seconds)
'play', // Play/pause playback
'fast-forward', // Fast forward by the seek time (default 10 seconds)
'progress', // The progress bar and scrubber for playback and buffering
'current-time', // The current time of playback
'duration', // The full duration of the media
'mute', // Toggle mute
'volume', // Volume control
'captions', // Toggle captions
'settings', // Settings menu
'pip', // Picture-in-picture (currently Safari only)
'airplay', // Airplay (currently Safari only)
'download', // Show a download button with a link to either the current source or a custom URL you specify in your options
'fullscreen' // Toggle fullscreen
];
const player = Plyr.setup('.js-player', { controls });
});
<script src="https://cdn.plyr.io/3.5.6/plyr.js"></script>
<link href="https://cdn.plyr.io/3.5.6/plyr.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment