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
This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →
Video
src sets the file, poster the cover image and title the name for screen readers.
<zb:media-player
src="../assets/media/sample-video.mp4"
poster="../assets/media/sample-poster.jpg"
title="Intro video"
/>
| Prop | Values |
|---|---|
src | File URL |
poster | Cover image (video only) |
title | Screen reader name; default "Video player" |
YouTube
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.
<zb:media-player src="https://www.youtube.com/watch?v=VIDEO_ID" title="Varyant tanımları" poster="/img/varyant-kapak.jpg" />
Audio
With audio, the player turns into a single-row audio bar.
<zb:media-player audio src="../assets/media/sample-audio.wav" title="Chord sample" />
| Prop | Values |
|---|---|
audio | true | false |
title | Screen reader name; default "Audio player" |
Captions and sources
Write WebVTT captions inside as <track> elements; for several file formats, pass sources instead of src.
<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>
| Prop | Values |
|---|---|
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?
| Prop | Type | Default | Description |
|---|---|---|---|
src | — | null | URL 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 | — | null | Image shown before playback starts (video only) |
audio | boolean | false | A single-row audio bar instead of the video frame |
title | — | null | Screen reader name; if omitted, "Video player" or "Audio player" |
preload | — | metadata | none | metadata | auto; passed to the media element |
autoplay | boolean | false | Starts playing when the page opens; most browsers block autoplay with sound, so use it with muted |
muted | boolean | false | Starts muted |
loop | boolean | false | Starts 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
Keyboard and accessibility
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.
<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
/>
| Prop | Values |
|---|---|
speeds | Speed list, e.g. [1, 1.5, 2]; [] removes the speed selector |
muted · loop · autoplay | Passed to the media element; browsers usually block autoplay with sound |
Inside Livewire
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).
<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
- 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"orclass="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-nocookieplayer, andposteris 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
captionsorsubtitlesadds a captions button to the bar; with several tracks, the button turns thedefaultone 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,
SpaceorKplays and pauses,←→skip back or forward five seconds,↑↓change the volume by 10%,Mmutes and unmutes,Fswitches to full screen,Cturns captions on and off, andHomeandEndjump 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.