Skip to content

Video Player

<py-video> provides a full-featured video player with auto-hiding controls, fullscreen, Picture-in-Picture, volume, and speed control.

Basic Usage

html
<py-video
  src="https://example.com/video.mp4"
  title="My Video"
></py-video>

With Poster Image

The poster image shows before playback starts. Click to play.

html
<py-video
  src="https://example.com/video.mp4"
  poster="https://example.com/thumbnail.jpg"
  title="My Video"
></py-video>

Aspect Ratio

Default is 16/9. Override with the aspect-ratio attribute:

html
<py-video src="video.mp4" aspect-ratio="4/3"></py-video>
<py-video src="short.mp4" aspect-ratio="9/16"></py-video>

Autoplay, Muted, Loop

html
<py-video
  src="background.mp4"
  autoplay
  muted
  loop
></py-video>

Note: Browsers block autoplay with audio. Use muted for autoplay to work reliably.

Theming

All themes work with <py-video>:

html
<py-video src="video.mp4" theme="dark"></py-video>
<py-video src="video.mp4" theme="midnight" accent="#ff6b6b"></py-video>

Controls

Controls auto-hide after 3 seconds during playback and reappear on hover or tap.

ControlDescription
Play/PauseToggle playback
Progress barSeek by dragging or clicking
VolumeSlide to adjust, click speaker to mute
SpeedChoose from 0.5x, 0.75x, 1x, 1.25x, 1.5x, 2x
Picture-in-PictureFloat the video in a corner
FullscreenEnter fullscreen mode

JavaScript API

js
const player = document.querySelector('py-video')

player.play()
player.pause()
player.requestFullscreen()
player.requestPiP()

player.volume = 0.5
player.muted = true
player.playbackRate = 1.5

console.log(player.currentTime)
console.log(player.duration)
console.log(player.paused)

player.addEventListener('py-fullscreen', (e) => {
  console.log('fullscreen:', e.detail.active)
})

Events

EventDetailDescription
py-playPlayback started
py-pausePlayback paused
py-endedVideo finished
py-time-update{ currentTime, duration }Fires during playback
py-fullscreen{ active: boolean }Fullscreen state changed
py-error{ code, format }Playback error

Browser Support

FeatureChromeFirefoxSafari
Fullscreen71+64+16.4+
Picture-in-Picture69+113+14+
Speed controlAllAllAll