martinbean/mux-php-laravel
Composer 安装命令:
composer require martinbean/mux-php-laravel
包简介
Laravel wrapper for the official Mux PHP SDK.
README 文档
README
Installation
composer require martinbean/mux-php-laravel
Configuration
By default, the package expects two environment variables to be defined:
MUX_CLIENT_IDMUX_CLIENT_SECRET
This should be a Mux access token ID and secret.
You can generate a Mux access token by:
- Logging into your Mux dashboard
- Going to “Settings”
- Then going to “Access Tokens”
Verifying webhook signatures
To verify webhook signatures from Mux, specify the signing secret for your webhook endpoint as the value of your MUX_WEBHOOK_SECRET environment variable. This means you will need to register your webhook endpoint in the Mux dashboard first.
Usage
API clients
The package will register default configuration based on the configured Mux access token. This means you can then type-hint a Mux client in your Laravel application, and it and its dependencies will be automatically resolved:
namespace App\Http\Controllers; use MuxPhp\Api\DirectUploadsApi; class UploadController extends Controller { protected DirectUploadsApi $uploads; public function __construct(DirectUploadsApi $uploads) { $this->uploads = $uploads; } }
Webhook handling
The package will also automatically register a route to listen for webhooks sent by Mux. The URI of this handler is /mux/webhook
The webhook handler is heavily based on Cashier’s webhook handler. When a webhook from Mux is received, an instance of the MartinBean\Laravel\Mux\Events\WebhookReceived event is dispatched containing the webhook’s payload.
You can define a listener that listens for this event:
namespace App\Listeners; use MartinBean\Laravel\Mux\Events\WebhookReceived; class MuxEventListener { public function handle(WebhookReceived $event): void { // Handle Mux webhook event... } }
This is where you would update models, etc in your application based on events from Mux:
public function handle(WebhookReceived $event): void
{
- // Handle Mux webhook event...
+ match ($event->payload['type']) {
+ 'video.asset.errored' => $this->handleVideoAssetErrored($event->payload),
+ 'video.asset.ready' => $this->handleVideoAssetReady($event->payload),
+ default => null, // unhandled event
+ };
}
+
+ protected function handleVideoAssetErrored(array $payload): void
+ {
+ // TODO: Retrieve associated video
+ // TODO: Update video status to 'errored'
+ // TODO: Notify user processing video errored
+ }
+
+ protected function handleVideoAssetReady(array $payload): void
+ {
+ // TODO: Retrieve associated video
+ // TODO: Update video status to 'ready'
+ // TODO: Notify user processing video succeeded
+ }
Mux Player
The package contains a Blade view component that makes displaying your Mux videos easy.
The only required property is a playback-id (in the case that the video has a “public” playback policy):
<x-mux::player playback-id="YOUR_PLAYBACK_ID" />
If your video has a “signed” playback policy, then you can provide the playback_token attribute:
<x-mux::player playback-id="YOUR_PLAYBACK_ID" playback-token="YOUR_PLAYBACK_TOKEN" />
In fact, any attributes are passed to the underlying Mux Player instance, so you can specify any other documented attributes such as metadata keys:
<x-mux::player playback-id="YOUR_PLAYBACK_ID" playback-token="YOUR_PLAYBACK_TOKEN" metadata-video-id="{{ $video->id }}" metadata-video-title="{{ $video->title }}" metadata-viewer-id="{{ Auth::id() }}" />
Manually including the Mux Player JavaScript library
By default, the <x-mux::player> component will include the required Mux Player JavaScript library from the jsDeliver CDN. If you do not want this, because maybe you’re installing Mux Player via a package such as npm or Yarn and building it with Vite, then you can pass the no-script attribute. You will then need to make sure you’re including the Mux Player JavaScript yourself:
@vite('resources/js/player.js') <x-mux::player no-script playback-id="YOUR_PLAYBACK_ID" />
Contribution
Contributions are always welcome. Please open a pull request with your proposed changes, with accompanying tests.
License
Licensed under the MIT License
martinbean/mux-php-laravel 适用场景与选型建议
martinbean/mux-php-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.45k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2024 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「video」 「laravel」 「mux」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 martinbean/mux-php-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 martinbean/mux-php-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 martinbean/mux-php-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
The yii2-videojs-widget is a Yii 2 wrapper for the [video.js](http://www.videojs.com/). A JavaScript and CSS library that makes it easier to work with and build on HTML5 video. This is also known as an HTML5 Video Player.
Display a video using native HTML5 video
Alfabank REST API integration
TYPO3 Plugin that displays YouTube-videos faster by loading the video-player on demand while displaying a cacheable preview picture.
The yii2-alipay-widget is a Yii 2 wrapper for the [video.js](http://www.videojs.com/). A JavaScript and CSS library that makes it easier to work with and build on HTML5 video. This is also known as an HTML5 Video Player.
统计信息
- 总下载量: 8.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 26
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-26