Player example
This example displays an overlay and hides the player controls and play button after 3 seconds of the video playing and prompts the user to login/register. When the user chooses to register or login through the form in the overlay, the overlay is hidden and the video plays. Test the functionality by clicking the buttons in the form.
(Note that the sample doesn't actually do any field validation or authentication, so clicking either Register or Login and then the password Submit button that appears will cause the video to play.)
See the Pen 18158-register-play-after-preview by Brightcove Learning Services (@rcrooks1969) on CodePen.
View the source code.
Using the CodePen
Development sequence
API/Plugin resources used
API Methods | API Events | Brightcove Player Plugins |
---|---|---|
play() | timeupdate | Display Overlay Plugin |
pause() | ||
on() | ||
off() | ||
addClass() | ||
removeClass() | ||
currentTime() |
Player/HTML configuration
This section details any special configuration needed during player creation. In addition, other HTML elements that must be added to the page, beyond the in-page embed player implementation code, are described.
Player configuration
No special configuration is required for the Brightcove Player you create for this sample.
Other HTML
Appropriate tags are used to link to the CSS and JavaScript for the Display Overlay Plugin.
Application flow
Before we dive into the code, let's look at the logic of the app:

The basic logic behind this application is:
- Configure the overlay.
- Pause video after three seconds of playing.
- Process the form.
- Start the video when the form filled out.
Configure the Overlay
Find the code which is labeled:
// ### Configure the Overlay ###
The overlay is configured to display at 3 seconds (causing the form to be displayed). The form is built in a long string as used by the overlay as overlayContent
.
Check, and act if preview time is passed
Find the code which is labeled:
// ### Act if preview time is passed ###
The code uses the timeupdate
event to continually call the event handler that checks to see if 3 seconds have passed. Note the player controls are hidden so the user can't play the video under the form. Also, the event listener is removed so the check on the time is no longer performed.
Process the form
Find the code which is labeled:
// ### Process the form ###
Standard HTML and JavaScript is used to process the form.
Play video when form filled out
Find the code which is labeled:
// ### Plays video when form filled out ###
When the form is filled out, the overlay form is hidden, the controls are displayed and the video is starts playing again.
Application styling
The extensive CSS controls the display of the form and size of the player.
Plugin code
Normally when converting the JavaScript into a Brightcove Player plugin nominal changes are needed. One required change is to replace the standard use of the ready()
method with the code that defines a plugin.
Here is the very commonly used start to JavaScript code that will work with the player:
videojs.getPlayer('myPlayerID').ready(function() {
var myPlayer = this;
...
);
You will change the first line to use the standard syntax to start a Brightcove Player plugin:
videojs.registerPlugin('pluginName', function(options) var myPlayer = this;
...
});
As mentioned earlier, you can see the plugin's JavaScript code in this document's corresponding GitHub repo: register-to-play-after-preview.js.
Using the plugin with a player
Once you have the plugin's CSS and JavaScript files stored in an Internet accessible location, you can use the plugin with a player. In Studio's PLAYERS module you can choose a player, then in the PLUGINS section add the URLs to the CSS and JavaScript files, and also add the Name and Options, if options are needed.