studio.Enabler#getContainerState() equals
studio.sdk.ContainerState#FS_EXPANDED for fullscreen exandables.
For interstials the component will be set as autoplay, for expandables, they
are set as not autoplay and call
component.getVideoElement().play() on expanded. studio.events.StudioEvent#VISIBLE event. To be safe, create it
at studio.events.StudioEvent#INIT. This is true even for
expandables.var collapsedViewport;
var expandedViewport;
var videoContainer;
var videoComp;
var isVideoCompCreated = false;
function setUpExpandLifeCycle() {
Enabler.addEventListener(
studio.events.StudioEvent.EXPAND_START,
expandStartHandler);
Enabler.addEventListener(
studio.events.StudioEvent.COLLAPSE_START,
collapseStartHandler);
}
function collapsedViewportClickHandler(e) {
Enabler.requestExpand();
}
function expandStartHandler() {
collapsedViewport.style.display = 'none';
expandedViewport.style.display = 'block';
Enabler.finishExpand();
if (!isVideoCompCreated) {
// Create the video component, only do this once and hide
// and show it subsequently.
videoComp = new studio.sdk.rad.Video({
id: 'YT Comedy Trailer',
autoplay: true, // Autoplays the first time.
controls: true,
sources: ['video.mp4'] // No need for Enabler.getUrl() here.
});
// Set the element it will decorate.
videoComp.setElement(videoContainer);
// Note: getVideoElement() returns real element now, should you want
// to set a poster attribute.
} else {
videoComp.getVideoElement().style.visibility = 'visible';
if (videoComp.getVideoElement().paused) {
videoComp.getVideoElement().play();
}
}
isVideoCompCreated = true;
}
function collapseStartHandler() {
collapsedViewport.style.display = 'block';
expandedViewport.style.display = 'none';
Enabler.finishCollapse();
videoComp.getVideoElement().style.visibility = 'hidden';
if (!videoComp.getVideoElement().paused) {
videoComp.getVideoElement().pause();
}
}
Enabler.loadModule(studio.module.ModuleId.RAD_VIDEO, function() {
// Enabler.loadModule waits for the Enabler to initialize so no need
// for extra isInitialized() check here.
collapsedViewport = document.querySelector('#collapsed');
expandedViewport = document.querySelector('#expanded');
videoContainer = document.querySelector('#video-container');
setUpExpandLifeCycle();
collapsedViewport.addEventListener(
'click',
collapsedViewportClickHandler,
false);
});
| rad.ui.Video | |
| studio.sdk.rad.Video | rad.ui.Video |
|
config
: !studio.sdk.rad.VideoConfig
The configuration object.
|
destroy()
Detroys a video component and preps it for garbage collection.
Only use this if you plan not to create another video component
on the same element.
|
||
getVideoElement()
⇒ HTMLVideoElement
Returns the video element that is a child of this component.
The video element is created in the constructor of this component.
Returns: HTMLVideoElement
The video element.
|
||
setElement(element)
Accepts a root DOM element for the component. This method is expected to
only be called once, after instantiation and before load().
Arguments:
|