videojs_element
Easily embed a modern, responsive Video.js player anywhere in your Drupal site using a simple Form API element. This module is perfect for adding videos to custom forms, with a key feature to prevent users from skipping ahead—ideal for training and educational content.
Features
This module provides a new Form API element, '#type' => 'videojs', which allows developers to embed videos declaratively within their forms. Its primary function is to simplify the process of adding a feature-rich video player without needing to write custom JavaScript or libraries.
- Simple Form API Integration: Add a video player to any form with just a few lines of PHP.
- Forward-Seek Prevention: An optional setting (
'#prevent_forward_seek' => TRUE) disables the progress bar, forcing users to watch a video from start to finish. This is ideal for compliance training, tutorials, or educational courses. - Fully Customizable: Control every aspect of the player, including autoplay (with mute), looping, controls, preload behavior, and aspect ratio (16:9, 4:3, etc.).
- Responsive Out-of-the-Box: The player is fully responsive and will adapt to any theme and screen size without extra configuration.
- Multiple Sources: Provide multiple video formats (e.g., MP4, WebM) for maximum browser compatibility.
Post-Installation
Once installed and enabled, there is no central configuration page for this module. All configuration is done directly within the Form API element definition in your custom code.
To use the module, simply define an element with '#type' => 'videojs' in your form builder function and pass in the required options, such as #sources. See the code examples on this page for guidance.
To see a working example immediately after installation, visit the demo page at:
/admin/config/content/videojs-example
This page demonstrates a sample video player with the forward-seek prevention feature enabled.
Additional Requirements
This module requires:
- Drupal 10 or later.
No external libraries need to be downloaded or installed. The required Video.js library and its CSS are loaded automatically from a CDN.
Recommended modules/libraries
There are no recommended modules or libraries at this time.
Similar projects
While other modules exist for embedding media, VideoJS Element is differentiated by its focus on providing a simple, developer-centric Form API element. Its lightweight nature and built-in feature for preventing forward seeking make it uniquely suited for applications where video playback control is essential for business or educational logic.
Supporting this Module
This module was originally developed by Haas Automation, Inc., and generalized for open-source release. If you would like to support its continued development, please contribute via the project issue queue.
Community Documentation
You can view a live demo of the module's functionality, including the seek prevention feature, on the built-in demo page:
/admin/config/content/videojs-example