Skip to content

Instantly share code, notes, and snippets.

@davekiss
Created March 17, 2025 13:29
Show Gist options
  • Save davekiss/e30c3d14177b7d21f883947dff3d8544 to your computer and use it in GitHub Desktop.
Save davekiss/e30c3d14177b7d21f883947dff3d8544 to your computer and use it in GitHub Desktop.
// Controlling a player (Vanilla JS)
<media-controller id="player">
<video
slot="media"
src="https://stream.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe/high.mp4"
preload="auto"
muted
></video>
<media-control-bar>
<media-play-button></media-play-button>
<media-mute-button></media-mute-button>
<media-time-range></media-time-range>
<media-time-display></media-time-display>
<media-fullscreen-button></media-fullscreen-button>
</media-control-bar>
</media-controller>
<button id="play-button">Play</button>
<script>
const video = document.querySelector('video');
const playButton = document.querySelector('#play-button');
playButton.addEventListener('click', () => {
if (video.paused) {
video.play();
playButton.textContent = 'Pause';
} else {
video.pause();
playButton.textContent = 'Play';
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment