Installation
composer require aldaflux/player-bundle dev-master
Ensure your project uses Symfony 4.2+ or 5.0+ (as per composer.json).
Enable the Bundle
Add to config/bundles.php:
return [
// ...
AldaFlux\PlayerBundle\AldaFluxPlayerBundle::class => ['all' => true],
];
First Use Case: Basic Player Integration Inject the player service in a controller or service:
use AldaFlux\PlayerBundle\Service\PlayerService;
class MediaController extends AbstractController
{
public function __construct(private PlayerService $playerService) {}
public function playMedia(string $mediaId): Response
{
$status = $this->playerService->play($mediaId);
return new JsonResponse(['status' => $status]);
}
}
src/Service/PlayerService.php (core logic).config/packages/aldaflux_player.yaml (default config).Media Playback
PlayerService methods:
$playerService->play($mediaId); // Start playback
$playerService->pause($mediaId); // Pause
$playerService->stop($mediaId); // Stop
$playerService->seek($mediaId, 120); // Seek to 120s
player.play, player.pause via Symfony’s event dispatcher:
$dispatcher->addListener('player.play', function (PlayEvent $event) {
// Custom logic (e.g., analytics, logging)
});
Configuration
config/packages/aldaflux_player.yaml:
aldaflux_player:
default_player: 'vjs' # e.g., 'vjs' (Video.js), 'hls'
media_root: '%kernel.project_dir%/public/media'
services:
AldaFlux\PlayerBundle\Player\CustomPlayer:
tags: ['aldaflux_player.player']
Twig Integration Embed players in templates:
{{ render(controller('AldaFluxPlayerBundle:Player:embed', {
mediaId: 'movie123',
player: 'vjs',
options: { autoplay: true }
})) }}
PlayerService in API endpoints to control playback remotely.asset() for static assets.PlayerService in PHPUnit:
$this->mockBuilder->getMockBuilder(PlayerService::class)
->disableOriginalConstructor()
->getMock();
Version Locking
dev-master; pin versions in composer.json to avoid breaking changes:
"aldaflux/player-bundle": "dev-master#1234567890"
Missing Events
player.error may not be documented. Inspect EventDispatcher for available events:
$events = $dispatcher->getListeners();
Player Initialization
APP_DEBUG=true) to see player service logs.media_root config).PlayerService calls.Custom Players
Implement PlayerInterface and tag as a service:
class MyPlayer implements PlayerInterface {
public function play(string $mediaId): bool { /* ... */ }
}
tags: ['aldaflux_player.player']
Media Storage
Extend MediaStorageInterface for custom storage (e.g., S3):
class S3MediaStorage implements MediaStorageInterface {
public function getUrl(string $mediaId): string { /* ... */ }
}
Register as a service and override aldaflux_player.media_storage config.
Event Subscribers Create subscribers for player events:
class PlayerAnalyticsSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents(): array {
return ['player.play' => 'onPlay'];
}
public function onPlay(PlayEvent $event) { /* ... */ }
}
default_player config value.media_root (e.g., movie123.mp4 → mediaId: movie123).How can I help you explore Laravel packages today?