hugomyb/filament-media-action 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hugomyb/filament-media-action

Composer 安装命令:

composer require hugomyb/filament-media-action

包简介

Automatically display your media (video, audio, document, image, ...) with an action

README 文档

README

Latest Version on Packagist Total Downloads

Automatically display your media (video, audio, pdf, image, ...) with an action in Filament. The package automatically detects the media extension to display the correct player.

Examples

example1 example2 example3 example4 example5 example6 example7

Installation

Note for Filament v3 users:
If your project is running on Filament v3, please install the 3.x version of this package:

composer require hugomyb/filament-media-action:^3.0

For Filament v4, simply install the latest version (default branch main).

You can install the package via composer:

composer require hugomyb/filament-media-action

Optionally, you can publish the view using

php artisan vendor:publish --tag="filament-media-action-views"

Optionally, you can publish the translations using

php artisan vendor:publish --tag="filament-media-action-translations"

Usage

Basic Usage

Like a classic Filament Action, you can use MediaAction anywhere (Forms, Tables, Infolists, Suffix and prefix, ...).

Simply provide the url of your media in the ->media() method. The package will then automatically detect your media extension for display.

MediaAction::make('tutorial')
    ->iconButton()
    ->icon('heroicon-o-video-camera')
    ->media('https://www.youtube.com/watch?v=rN9XI9KCz0c&list=PL6tf8fRbavl3jfL67gVOE9rF0jG5bNTMi')

Available options

Autoplay

You can enable autoplay for video and audio by using the ->autoplay() method.

MediaAction::make('media-url')
    ->media(fn($record) => $record->url)
    ->autoplay()

You can also pass a closure in the method and access $record and $mediaType :

MediaAction::make('media-url')
    ->media(fn($record) => $record->url)
    ->autoplay(fn($record, $mediaType) => $mediaType === 'video')

$mediatype can return "youtube", "audio", "video", "image" or "pdf".

Force Media Type

If the automatic media type detection fails (common with local development URLs or files without extensions), you can force the media type:

use Hugomyb\\FilamentMediaAction\\Actions\\MediaAction;

MediaAction::make('video')
    ->media('https://myapp.test/video.MOV')
    ->mediaType(MediaAction::TYPE_VIDEO) // Force video type (preferred)

Available media types (constants): MediaAction::TYPE_VIDEO, MediaAction::TYPE_AUDIO, MediaAction::TYPE_IMAGE, MediaAction::TYPE_PDF, MediaAction::TYPE_YOUTUBE. Strings remain supported for backward compatibility.

Preload

To control the preload behavior, use the ->preload() method. By default, it is set to true, which means the media will preload automatically. You can set it to false to disable preloading (this is helpful to avoid "Autoplay failed or was blocked" errors in some browsers).

MediaAction::make('media-url')
    ->media(fn($record) => $record->url)
    ->autoplay()
    ->preload(false)

Control list

You can control the media player's interface by using the control list options. These options allow you to disable certain features of the HTML5 video and audio players.

Note: Control list options only work in Chromium-based browsers (Chrome, Edge, etc.) and have no effect in Firefox, Safari, or other browsers.

You can use the following convenience methods:

MediaAction::make('media-url')
    ->media(fn($record) => $record->url)
    ->disableDownload() // Prevents the user from downloading the media
    ->disableFullscreen() // Prevents the user from viewing the video in fullscreen
    ->disableRemotePlayback() // Prevents the user from using remote playback (e.g., Chromecast)

Each of these methods can accept a boolean or a closure:

MediaAction::make('media-url')
    ->media(fn($record) => $record->url)
    ->disableDownload(fn($record) => $record->is_protected)

You can also set the control list directly using the controlsList method:

MediaAction::make('media-url')
    ->media(fn($record) => $record->url)
    ->controlsList(['nodownload', 'nofullscreen', 'noremoteplayback'])

Or with a closure:

MediaAction::make('media-url')
    ->media(fn($record) => $record->url)
    ->controlsList(fn($record) => $record->is_protected ? ['nodownload'] : [])

Other options

You can customize the modal as you wish in the same way as a classic action (see https://filamentphp.com/docs/4.x/actions/modals).

If there is an existing record, you can access it by passing a closure to ->media() method.

Accessible parameters: $livewire, $data, $model, $record, $arguments.

Example :

MediaAction::make('media-url')
    ->modalHeading(fn($record) => $record->name)
    ->modalFooterActionsAlignment(Alignment::Center)
    ->media(fn($record) => $record->url)
    ->extraModalFooterActions([
        MediaAction::make('media-video2')
            ->media('https://www.youtube.com/watch?v=9GBXqWKzfIM&list=PL6tf8fRbavl3jfL67gVOE9rF0jG5bNTMi&index=3')
            ->extraModalFooterActions([
                MediaAction::make('media-video3')
                    ->media('https://www.youtube.com/watch?v=Bvb_vqzhRQs&list=PL6tf8fRbavl3jfL67gVOE9rF0jG5bNTMi&index=5')
            ]),

        Tables\Actions\Action::make('open-url')
            ->label('Open in browser')
            ->url(fn($record) => $record->url)
            ->openUrlInNewTab()
            ->icon('heroicon-o-globe-alt')
    ])

As shown in the example above, you can chain MediaActions together with ->extraModalFooterActions() method.

Customizing the modal view

You can customize the modal view by publishing the view using :

php artisan vendor:publish --tag="filament-media-action-views"

Then, in the view, you can access :

  • $mediaType: To retrieve the type of your media, which can be “youtube”, “audio”, “video”, “image” or “pdf”.
  • $media : To retrieve the url of your media

Supported media extensions

Type Extensions
Video mp4, avi, mov, webm, mkv, flv, wmv, 3gp, ogv, m4v
Audio mp3, wav, ogg, aac, flac, m4a, wma
Documents pdf
Image jpg, jpeg, png, gif, bmp, svg, webp, tiff, ico

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

hugomyb/filament-media-action 适用场景与选型建议

hugomyb/filament-media-action 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 167.95k 次下载、GitHub Stars 达 55, 最近一次更新时间为 2024 年 07 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「hugomyb」 「filament-media-action」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 hugomyb/filament-media-action 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hugomyb/filament-media-action 我们能提供哪些服务?
定制开发 / 二次开发

基于 hugomyb/filament-media-action 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 167.95k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 55
  • 点击次数: 29
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 55
  • Watchers: 2
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-30