ultraviolettes/filament-audio-field-column
Installation:
composer require ultraviolettes/filament-audio-field-column
Publish the config (if needed) with:
php artisan vendor:publish --provider="Ultraviolettes\FilamentAudio\FilamentAudioServiceProvider"
First Use Case: Display an audio preview in a Table Column:
use Ultraviolettes\FilamentAudio\Tables\Columns\AudioColumn;
public static function table(Table $table): Table
{
return $table->columns([
AudioColumn::make('audio_file')
->label('Listen'),
]);
}
audio_file field contains a valid URL (local or remote) pointing to an audio file (e.g., storage/audio/sample.mp3 or https://example.com/audio.mp3).AudioColumn::make('audio_path')
->size(36) // Default: 40px
->progressColor('green-500') // Tailwind color
->showDuration() // Adds time display
AudioColumn::make('id')
->audioUrl(fn ($record) => route('audio.download', $record))
use Ultraviolettes\FilamentAudio\Forms\Components\AudioUpload;
AudioUpload::make('audio_file')
->directory('audio') // Stores in `storage/app/audio/`
->openable() // Allows file selection
AudioUpload::make('audio_file')
->existingFileUrl(fn ($record) => $record->audio_url)
use Ultraviolettes\FilamentAudio\Infolists\Components\AudioPlayer;
AudioPlayer::make('audio_url')
->size(50)
->volumeControl() // Adds volume slider
Storage::url() to generate URLs for local files:
AudioColumn::make('file')
->audioUrl(fn ($record) => Storage::url($record->file_path))
https://example.com/audio.mp3). Relative paths (e.g., /audio.mp3) may fail.$record->audio_duration ??= AudioHelper::getDuration($record->audio_url);
config/filament-audio.php:
'default' => [
'size' => 48,
'progress_color' => 'blue-500',
'auto_pause' => true,
],
document.addEventListener('filament-audio:play', (e) => {
console.log('Playing:', e.detail.url);
});
CORS Issues:
Header set Access-Control-Allow-Origin "*"
File Format Support:
<audio> element. Test with MP3, WAV, or OGG for broad compatibility.Auto-Pause Conflicts:
auto_pause feature (only one player plays at a time) may interfere with UX in tables with many rows.AudioColumn::make('audio')->autoPause(false)
Alpine.js Conflicts:
AudioColumn::make('audio')->id('unique-audio-player')
Console Errors:
Check the browser console for 404 (file not found) or 403 (CORS) errors.
AudioColumn::make('dummy')->audioUrl('https://example.com/test.mp3')
Duration Calculation:
If durations are NaN, ensure the audio file is accessible and not corrupted. Use a tool like FFmpeg to verify:
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp3
Custom Styling:
Override Blade components in resources/views/vendor/filament-audio/.
Example: Modify the progress bar in audio-progress.blade.php.
Add Metadata: Extend the column to display metadata (e.g., artist, album) from the audio file:
AudioColumn::make('audio')
->extraAttributes(fn ($record) => [
'data-artist' => $record->artist,
])
Then target it in CSS/JS:
document.querySelector('[data-artist]').dataset.artist;
Server-Side Duration: Cache durations server-side to avoid repeated client-side calculations:
// In a model observer or accessor
public function getAudioDurationAttribute()
{
return cache()->remember("audio_duration_{$this->id}", now()->addHours(1), function () {
return AudioHelper::getDuration($this->audio_url);
});
}
AudioColumn::make('audio')
->lazy() // Only loads when scrolled into view
AudioColumn::make('audio')
->progressColor('emerald-400 dark:emerald-300')
AudioColumn::make('audio')
->ariaLabel('Play audio preview')
How can I help you explore Laravel packages today?