hugomyb/filament-media-action
Filament action to preview media (video, audio, PDF, images, etc.) anywhere in your app (forms, tables, infolists, prefix/suffix). Just pass a media URL and it auto-detects the extension to render the right player/viewer.
Installation:
composer require hugomyb/filament-media-action
For Filament v3, use composer require hugomyb/filament-media-action:^3.0.
First Use Case: Add a media action to a Filament resource table or form:
use Hugomyb\FilamentMediaAction\Actions\MediaAction;
MediaAction::make('Play Video')
->iconButton()
->icon('heroicon-o-video-camera')
->media('https://example.com/video.mp4');
Table Actions:
Tables\Actions\Action::make('View Media')
->action(MediaAction::make('media')
->media(fn($record) => $record->media_url)
->modalHeading(fn($record) => $record->title)
);
Form Fields:
use Filament\Forms\Components\Actions\Action;
Action::make('Preview')
->action(MediaAction::make('preview')
->media(fn($get, $record) => $get('media_url') ?? $record->media_url)
);
Nested Media Actions:
MediaAction::make('Main Media')
->media(fn($record) => $record->primary_url)
->extraModalFooterActions([
MediaAction::make('Secondary Media')
->media(fn($record) => $record->secondary_url),
]);
->media(fn($record) => $record->getMediaUrl())
->autoplay(fn($record, $mediaType) => $mediaType === 'video' && $record->is_premium)
->modalWidth('6xl')
->modalMaxWidth('100%')
Media Type Detection:
http://myapp.test/video.MOV) may fail auto-detection. Use ->mediaType(MediaAction::TYPE_VIDEO) to force the type.Closure Dependencies:
$get/$set may be null. Guard closures:
->media(fn($get, $record) => $get ? $get('url') : $record->url)
YouTube Embeds:
->preload(false) to avoid browser errors.MIME Type Conflicts:
->mediaType('video')) may cause "Loading..." issues if the MIME type is invalid. Prefer constants:
->mediaType(MediaAction::TYPE_VIDEO)
->media(fn($record) => {
$url = $record->url;
$type = app(MediaAction::class)->getMediaType($url);
logger()->debug("Detected type for $url: $type");
return $url;
})
php artisan vendor:publish --tag="filament-media-action-views"
Custom Players:
resources/views/vendor/filament-media-action/modal.blade.php) to integrate third-party players (e.g., Plyr, Video.js).Translation:
php artisan vendor:publish --tag="filament-media-action-translations"
Media Type Extensions:
getSupportedExtensions() method in MediaTypeDetector (via service provider binding) to support custom formats.->preload(true) for large media to reduce initial load time.->modalMaxWidth('100%') to defer modal rendering until clicked.How can I help you explore Laravel packages today?