Install the Bundle
Run composer require azine/video.js-bundle:~4.7 to add the bundle to your project.
Register the Bundle
Add new Azine\VideoJsBundle\AzineVideoJsBundle() to your AppKernel.php under registerBundles().
Install Assets
Run php app/console assets:install web (or --symlink for development) to copy the CSS/JS files to your web/bundles/azinevideojs/ directory.
Include in a Twig Template Reference the assets in your layout or template:
<link rel="stylesheet" href="{{ asset('bundles/azinevideojs/css/video-js.min.css') }}">
<script src="{{ asset('bundles/azinevideojs/js/video.min.js') }}"></script>
Basic Video Player Usage Embed a video in Twig:
<video
id="my-video"
class="video-js vjs-default-skin"
controls
preload="auto"
width="640"
height="264"
data-setup='{}'>
<source src="{{ asset('path/to/video.mp4') }}" type="video/mp4">
<p class="vjs-no-js">
To view this video please enable JavaScript, and consider upgrading to a
web browser that supports HTML5 video
</p>
</video>
Use the bundle to replace Flash-based video players with an HTML5-compatible solution. Ideal for:
Asset Management
assets:install for production (copies files) or --symlink for development (symlinks for live updates).Twig Integration
azine_video_js_path()) for dynamic asset paths.{% block video_js %}
{{ parent() }}
<script>
videojs('my-video', {
controls: true,
autoplay: false,
width: 640
});
</script>
{% endblock %}
Dynamic Video Sources
{% for video in videos %}
<video
id="video-{{ video.id }}"
class="video-js"
data-setup='{ "controls": true }'>
{% for source in video.sources %}
<source src="{{ asset(source.path) }}" type="{{ source.type }}">
{% endfor %}
</video>
{% endfor %}
Custom Skins/Themes
<link rel="stylesheet" href="{{ asset('bundles/azinevideojs/css/video-js.css') }}">
<link rel="stylesheet" href="{{ asset('css/custom-video-skin.css') }}">
Event Handling
// In a JS file
document.addEventListener('DOMContentLoaded', function() {
var player = videojs('my-video');
player.on('play', function() { console.log('Playback started!'); });
});
Symfony\Bridge\Doctrine\Form\Type\EntityType to select videos from a database.loading="lazy" for better performance on long pages..video-js {
max-width: 100%;
}
Asset Paths in Development
--symlink, ensure your dev server (e.g., php -S localhost:8000) follows symlinks. Test with php app/console assets:install --symlink web and verify paths in Twig.Version Mismatches
web/bundles/azinevideojs/ or fork the bundle.Twig Autoloading
asset() paths, clear the cache:
php app/console cache:clear
Flash Fallback
<p class="vjs-no-js"> fallback, but ensure your project’s base template has JavaScript enabled. Test with:
php app/console debug:config --env=prod | grep javascript
CORS Issues
F12) for 404s on asset paths. Common fixes:
assets:install again.web/bundles/azinevideojs/ exists and is readable.video.min.js is loaded after the <video> element.data-setup attribute is present or videojs() is called manually.Resources/config/services.yml or config.yml, meaning it’s purely asset-based. Customization requires manual overrides.web/bundles/azinevideojs/css/ or use a CDN link to a newer version.Custom Asset Paths
Resources/public/ directory in your project:
src/Acine/VideoJsBundle/Resources/public/
├── css/video-js.css # Override default CSS
└── js/video.js # Override default JS
Resources/public/ takes precedence in assets:install.Twig Extensions
// src/Acine/VideoJsBundle/Twig/Extension/VideoJsExtension.php
class VideoJsExtension extends \Twig_Extension
{
public function getFunctions()
{
return [
new \Twig_SimpleFunction('azine_video_js', [$this, 'renderPlayer']),
];
}
public function renderPlayer(array $config, string $id)
{
// Logic to generate Twig/HTML for the player
}
}
Resources/config/services.yml:
services:
acine.videojs.twig.extension:
class: Acine\VideoJsBundle\Twig\Extension\VideoJsExtension
tags:
- { name: twig.extension }
Event Listeners
// src/Acine/VideoJsBundle/EventListener/VideoJsListener.php
class VideoJsListener
{
public function onKernelRequest(GetResponseEvent $event)
{
// Example: Force autoplay for specific routes
if ($event->getRequest()->attributes->get('_route') === 'media_play') {
// Inject JS via Symfony's Response or use a Twig block
}
}
}
services.yml:
services:
acine.videojs.listener:
class: Acine\VideoJsBundle\EventListener\VideoJsListener
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
Plugin Integration
<script src="{{ asset('bundles/azinevideojs/js/plugins/videojs-http-streaming.min.js') }}"></script>
<script>
videojs('my-video', {
plugins: { hls: true }
});
</script>
How can I help you explore Laravel packages today?