Skip to main content
VideoField ← Back to Table of Contents

Summary

Custom video player with optional YouTube embed, skip controls, PiP, fullscreen, and compact control layout.
ClassBjanczak\FilamentFlexFields\Filament\Forms\Components\VideoField
State typestring|null — video URL or YouTube/Vimeo link
Model cast'video_url' => 'string'
FieldTypevideo
Playgroundvideo-field slug in Flex Fields playground

Basic usage

HTML5 video with poster

use Bjanczak\FilamentFlexFields\Filament\Forms\Components\VideoField;

VideoField::make('tutorial')
    ->src('https://cdn.example.com/tutorial.mp4')
    ->poster('/images/tutorial-poster.jpg')
    ->title('Getting Started')
    ->subtitle('Learn the basics in 5 minutes')
    ->skipSeconds(15)
    ->pictureInPictureable()
    ->compactControls();

YouTube embed from state

use Bjanczak\FilamentFlexFields\Filament\Forms\Components\VideoField;

VideoField::make('promo_video')
    ->label('Promo Video')
    ->default('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
    ->ratio('16:9')
    ->youtubeNoCookie()
    ->autoHideControls();

State & validation

Stored value

State string = direct video URL or YouTube/Vimeo URL.
$record->video_url; // string|null — e.g. "https://www.youtube.com/watch?v=..."

Validation rules

Built-in validation ensures the URL is a valid string and matches supported media patterns.
RuleDetail
nullableState may be empty
stringState must be string when present
media_urlInternal rule checking for valid Mapbox/YouTube/Vimeo/Direct patterns

Configuration API

All methods accept Closure unless noted.
MethodTypeDefaultDescription
src(string|Closure|null $src)SetupnullStatic video source (overrides state)
poster(string|Closure|null $poster)SetupnullVideo poster image URL
title(string|Closure|null $title)SetupnullOverlay title
subtitle(string|Closure|null $subtitle)SetupnullOverlay subtitle
ratio(string|Closure|null $ratio)Setup'16:9'Aspect ratio (e.g. 16:9, 4:3, 1:1)
fullWidth(bool|Closure $condition = true)SetupfalseExpand player to fill container width
controls(bool|Closure $condition = true)SetuptrueShow playback controls
nativeControls(bool|Closure $condition = true)SetupfalseUse browser native controls
autoplay(bool|Closure $condition = true)SetupfalseStart playback automatically
loop(bool|Closure $condition = true)SetupfalseRestart video when finished
muted(bool|Closure $condition = true)SetupfalseStart playback muted
playsInline(bool|Closure $condition = true)SetuptruePlay inline on mobile devices
skipSeconds(int|Closure $seconds)Setup10Seconds to skip forward/backward
fullscreenable(bool|Closure $condition = true)SetuptrueEnable fullscreen mode
autoHideControls(bool|Closure $condition = true)SetuptrueHide controls when inactive
pictureInPictureable(bool|Closure $condition = true)SetupfalseEnable Picture-in-Picture mode
volumeControl(bool|Closure $condition = true)SetuptrueShow volume slider
allowYoutube(bool|Closure $condition = true)SetuptrueEnable YouTube support
allowVimeo(bool|Closure $condition = true)SetuptrueEnable Vimeo support
youtubeNoCookie(bool|Closure $condition = true)SetuptrueUse youtube-nocookie.com
controlsLayout(string|Closure $layout)Setup'default'default or compact
playIcon(...)SetupPlayFillCustom play icon
pauseIcon(...)SetupPauseFillCustom pause icon
volumeIcon(...)SetupVolumeFillCustom volume icon
muteIcon(...)SetupVolumeSlashFillCustom mute icon
fullscreenIcon(...)SetupExpandCustom fullscreen icon
placeholderIcon(...)SetupVideoCustom placeholder icon

ratio()

Supports standard aspect ratios. Invalid strings throw an InvalidArgumentException.
VideoField::make('video')->ratio('4:3');
VideoField::make('video')->ratio('1:1');

controlsLayout()

Use compact for a minimal control bar:
VideoField::make('video')->compactControls();

Real-world examples

Background video (Hero)

VideoField::make('hero_video')
    ->src('/videos/hero.mp4')
    ->autoplay()
    ->loop()
    ->muted()
    ->controls(false)
    ->fullWidth();

YouTube training video

VideoField::make('training')
    ->label('Internal Training')
    ->allowYoutube()
    ->youtubeNoCookie()
    ->autoHideControls()
    ->pictureInPictureable();

Playground

/admin/flex-fields-playground/video-field See Playground for setup.
ComponentWhen to use instead
AudioFieldFor audio-only playback
FlexFileUploadTo allow users to upload video files
LinkPreviewFieldFor simple link previews with thumbnails

CSS classes (reference)

ClassRole
fff-video-field-fieldRoot wrapper
fff-video-field-field--{sm|md|lg}Size modifier
fff-video-field__stageVideo area
fff-video-field__controlsControl bar
fff-video-field__controls--compactCompact layout modifier
fff-video-field__metadataTitle/subtitle overlay

Performance

MechanismWhat it does
Lazy LoadingVideo assets and Alpine components load only when the field is visible
YouTube FacadeShows a thumbnail/poster until the user clicks play to save bandwidth
Safe URLsAutomatic sanitization of media URLs for security