v0.0.2
Demos (demo panel, opens in a new tab)

Media player

Plays video and audio files with one control bar that matches the theme: play/pause, seek bar, time, volume, speed and full screen.

zb:media-player zubazar/ui-pro

PRO

This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →

Video

Video: view
BLADE

src sets the file, poster the cover image and title the name for screen readers.

blade
<zb:media-player
    src="../assets/media/sample-video.mp4"
    poster="../assets/media/sample-poster.jpg"
    title="Intro video"
/>
PropValues
srcFile URL
posterCover image (video only)
titleScreen reader name; default "Video player"

YouTube

BLADE

When src is a YouTube address (watch, youtu.be, embed, shorts), the player shows a cover and loads nothing from YouTube until the visitor presses play.

blade
<zb:media-player src="https://www.youtube.com/watch?v=VIDEO_ID" title="Varyant tanımları" poster="/img/varyant-kapak.jpg" />

Audio

Audio: view
BLADE

With audio, the player turns into a single-row audio bar.

blade
<zb:media-player audio src="../assets/media/sample-audio.wav" title="Chord sample" />
PropValues
audiotrue | false
titleScreen reader name; default "Audio player"

Captions and sources

Captions and sources: view
BLADE

Write WebVTT captions inside as <track> elements; for several file formats, pass sources instead of src.

blade
<zb:media-player
    :sources="[
        ['src' => '../assets/media/sample-video.webm', 'type' => 'video/webm'],
        ['src' => '../assets/media/sample-video.mp4', 'type' => 'video/mp4'],
    ]"
    poster="../assets/media/sample-poster.jpg"
    title="Intro with captions"
>
    <track kind="captions" src="../assets/media/sample-captions-tr.vtt" srclang="tr" label="Turkish" default>
</zb:media-player>
PropValues
sources[['src' => …, 'type' => 'video/webm'], …] or a plain array of URLs
(content)<track> elements; the track marked default starts on

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
src—nullURL of the media file
sources—[]Several formats: [['src' => …, 'type' => 'video/mp4'], …] or a plain array of URLs; the browser plays the first one it supports
poster—nullImage shown before playback starts (video only)
audiobooleanfalseA single-row audio bar instead of the video frame
title—nullScreen reader name; if omitted, "Video player" or "Audio player"
preload—metadatanone | metadata | auto; passed to the media element
autoplaybooleanfalseStarts playing when the page opens; most browsers block autoplay with sound, so use it with muted
mutedbooleanfalseStarts muted
loopbooleanfalseStarts over when it ends
speeds—[0.5, 0.75, 1, 1.25, 1.5, 2]Values in the speed selector; [] hides the speed selector
(attributes)— — id, class, wire:key, x-on:*, data-* … are added to the root element (class is merged); if class contains aspect-*, the 16:9 ratio is not applied

Slots: default: <track> (caption) or additional <source> elements added inside the media element.

Advanced

2 examples

Keyboard and accessibility

Keyboard and accessibility: view
BLADE

Keyboard shortcuts work while focus is in the player; the key list is in the Developer notes. speeds sets the speed list, and muted and loop are passed to the media element as they are.

blade
<zb:media-player
    src="../assets/media/sample-video.mp4"
    poster="../assets/media/sample-poster.jpg"
    title="Keyboard test"
    :speeds="[1, 1.5, 2]"
    muted
    loop
/>
PropValues
speedsSpeed list, e.g. [1, 1.5, 2]; [] removes the speed selector
muted · loop · autoplayPassed to the media element; browsers usually block autoplay with sound

Inside Livewire

BLADE

To change the source, give the player a wire:key that changes with it; Livewire replaces the old player with a new one. Media events don't bubble, so add listeners to the root with .capture (e.g. x-on:ended.capture).

blade
<div>
    <zb:media-player
        :src="$lesson->video_url"
        :poster="$lesson->cover_url"
        :title="$lesson->title"
        wire:key="lesson-video-{{ $lesson->id }}"
        x-on:ended.capture="$wire.markCompleted()"
    />

    <zb:button wire:click="nextLesson" class="mt-4">Next lesson</zb:button>
</div>

Developer notes

Events, hooks and details
  • If JavaScript does not run, the browser's own controls appear and the file still plays.
  • The frame fills the width of its container at 16:9; for a different ratio, pass class="aspect-square" or class="aspect-[4/3]".
  • Clicking the video plays or pauses it. During playback, the controls hide if the mouse doesn't move for a few seconds; moving the mouse or tabbing to a control brings them back.
  • When the visitor presses play, a YouTube video opens in the youtube-nocookie player, and poster is the cover's picture. In a modal or drawer the video stops when it closes; without JavaScript the button opens the video on YouTube.
  • As the audio bar gets narrower, the volume slider hides first, then the speed selector; this follows the player's width, not the screen's. The audio layout has no cover image, full screen or captions button.
  • A track of kind captions or subtitles adds a captions button to the bar; with several tracks, the button turns the default one on and off, or the first one. Captions sit above the control bar and move down when the bar hides.
  • The component's root has wire:ignore: when another part of the page updates, Livewire leaves the player alone and playback isn't interrupted.
  • On a page without Alpine, add the listener with player.addEventListener('ended', …, true); the player doesn't need Alpine.
  • The full screen button shows only when the browser allows it. Inside an iframe loaded from another domain, add allow="fullscreen" to the iframe; on iPhone, full screen opens in the video's own player.

Accessibility

Keyboard
While focus is in the player, Space or K plays and pauses, ← → skip back or forward five seconds, ↑ ↓ change the volume by 10%, M mutes and unmutes, F switches to full screen, C turns captions on and off, and Home and End jump to the start or the end. On the volume slider the arrow keys, and on the speed selector all keys, do that control's own job.
Screen readers
Button names change with the state ("Play" / "Pause", "Mute" / "Unmute", "Full screen" / "Exit full screen"); the seek bar announces its value as "1:05 / 3:20".
Focus and motion
Focus rings are always visible while navigating with the keyboard; if reduced motion is on in the operating system, transition animations are off.
Zubazar UI · ZubazarDesigned for people.