ad-video
Description
The <ad-video> tag creates a video player instance within the ad. This player functions differently than the standard HTML5 video element in a number of ways:
- It automatically tracks video view and interaction data when trafficked through the Specless platform
- It automatically pauses when the ad goes out of view
- It enforces muting when autoplay is enabled
- It has options to force the video to fill its parent container
- Allows an alternative set of simplified controls to be used
- Allows YouTube videos to be set as the source
Child Elements
Example Usage
<!-- Basic Example -->
<ad-video id="playerId" name="My Awesome Video" src="/assets/video.mp4" simple-controls poster="/assets/poster.jpg"></ad-video>
Must Include a Unique ID
The
<ad-video>element must include a unique value for theidattribute.
Attributes
| Name | Value | Default Value | Example(s) | Description |
|---|---|---|---|---|
id | string | Required | myPlayer | Required. A unique name to identify the player. Cannot be used by any other element. |
player-type | html5 youtube | html5 | html5 | Sets the type of technology driving video playback |
src | string | /assets/video.mp4http://videocdn.com/video.mp4https://www.youtube.com/watch?v=sGbxmsDFVnE | The path to the video assets in the assets folder or an external URL or the URL of a YouTube video (if player-type has been set to youtube). | |
name | string | defaults to the src value | Video Version A | A name to identify the specific piece of video content that is currently loaded in the video player instance. Used to differentiate tracking data for various videos that may load in the same player. |
sizing | contain cover | contain | cover | Forces video to either fill it's parent container (cover), or letter-box within the container (contain). Functions similar to the background-size properties of the same name in css. |
autoplay | boolean | Determines if the video should auto-play when auto-play capabilities are allowed (i.e. not allowed on mobile). Presence of the attribute is true. false otherwise. | ||
controls | boolean | false | Determines if the video should have controls. Presence of the attribute is true. false otherwise. | |
simple-controls | boolean | false | Enables simplified controls. Presence of the attribute is true. false otherwise. | |
preload | boolean | false | Determines if the video should preload as soon as it is on the page. Presence of the attribute is true. false otherwise. | |
poster | string | null | /assets/poster.jpg | Path to an image in the /assets/ directory to use as a poster image. |
muted | boolean | false | Should the video start muted. Presence of the attribute is true. false otherwise. | |
wallpaper | boolean | false | Sets the video to sizing: cover, autoplay: true, controls: false, loop: true. Presence of the attribute is true. false otherwise. | |
loop | boolean | false | Determines if the video should restart once complete. Presence of the attribute is true. false otherwise. | |
aspect | string | 16x9 | 4x3 | Notes the aspect ratio of video so it can resize proportionately. Does not set or maintain the aspect ratio of the video element. |
audio-hover | boolean | false | Video will always be muted unless the mouse is hovered over the video. Presence of the attribute is true.false otherwise. | |
view-toggle-off | boolean | false | At default, the video pauses whenever the ad goes out of view. This toggles that feature off. Presence of the attribute is true.false otherwise. |
Javascript API
Getting the Player Instance
ad.plugins.Video.get("myPlayer").ready(function(player) {
var myPlayer = player;
// Run your code here to control the video player
myPlayer.play();
myPlayer.pause();
});
Basic Methods
Below are the basic methods used to control video playback. The ad-video element uses video.js, so additional methods can be within the video.js documentation below.
.play()
.play()Starts media playback.
player.play() // Plays the video
.pause()
.pause()Stops media playback.
player.pause() // Pauses the video
.paused()
.paused()Checks if the player is paused. Returns true or false.
var isPaused = player.paused() // Returns true or false
.muted(muted)
.muted(muted)Gets or sets the current muted state of the player.
var isMuted = player.muted(); // Returns true of false
if (isMuted === false) {
player.muted(true) // Mutes the player
}
.currentTime(time)
.currentTime(time)Gets or sets the current time of the video.
var currentTime = player.currentTime(); // Returns the current time of playback in seconds
player.currentTime(120); // Sets the current playback time to 2 minutes
.duration()
.duration()Gets the total length of the current video.
var duration = player.duration() // Returns the length of the video
.ended()
.ended()Returns true/false if the video has ended or not.
if (player.ended() === true) {
// Do something if the video has ended
}
.on(event, callback)
.on(event, callback)Runs callback when the event event is fired by the player.
player.on('play', function() {
// Do something when the ad plays
}
player.on('pause', function() {
// Do something when the ad pauses
}
Events that can be passed into the .on() function are as follows:
endedFired when video playback ends.errorFired when an error occurs.loadeddataFired when the player has downloaded data at the current playback position.loadedmetadataFired when the player has initial duration and dimension information.timeupdateFired when the current playback position has changed * During playback this is fired every 15-250 milliseconds, depending on the playback technology in use.playFired when media playback starts.pauseFired when media playback stops.useractiveFired when the user is active, e.g. moves the mouse over the player.userinactiveFired when the user is inactive, e.g. a short delay after the last mouse move or control interaction.volumechangeFired when the volume changes.
Updated less than a minute ago
