Video Player component that enables the user to play a video with metric reporting. This component is as bare bones as possible and supports only one single progressive video. No convenience callbacks are available and the video does not do any smart buffering.
For more information, see Video Player.
The following diagram details the Video Player architecture:

Note: If you'd like to play video without the added weight of using a component, this component is a wrapper around the VideoController API.
import com.google.ads.studio.HtmlEnabler; import com.google.ads.studio.events.StudioVideoEvent; import flash.events.MouseEvent; HtmlEnabler.getInstance().init(this); videoPlayer.addEventListener( StudioVideoEvent.STATE_CHANGE, function (event:StudioVideoEvent):void { if (videoPlayer.isVideoStopped()) { postVideoAnimation.play(); } else { postVideoAnimation.gotoAndStop(1); } }); // The following listeners are for instances of buttons on the stage. playBtn.addEventListener( MouseEvent.CLICK, function (event:MouseEvent):void { videoPlayer.play(); }); pauseBtn.addEventListener( MouseEvent.CLICK, function (event:MouseEvent):void { videoPlayer.pause(); }); stopBtn.addEventListener( MouseEvent.CLICK, function (event:MouseEvent):void { videoPlayer.stop(); }); muteBtn.addEventListener( MouseEvent.CLICK, function (event:MouseEvent):void { videoPlayer.mute(); }); unmuteBtn.addEventListener( MouseEvent.CLICK, function (event:MouseEvent):void { videoPlayer.unmute(); }); seekNearEndBtn.addEventListener( MouseEvent.CLICK, function (event:MouseEvent):void { videoPlayer.seek( videoPlayer.getTotalSeconds() - 5); });
Events
Name | Type | Description |
---|---|---|
BACKWARDS_SEEK | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoBackwardsSeekHandler:Function = function( event:StudioVideoEvent):void { trace("Video seeks backward."); }; videoComponentInstance.addEventListener( StudioVideoEvent.BACKWARDS_SEEK, videoBackwardsSeekHandler); |
COMPLETE | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoCompleteHandler:Function = function( event:StudioVideoEvent):void { trace("Video completes playing."); }; videoComponentInstance.addEventListener( StudioVideoEvent.COMPLETE, videoCompleteHandler); |
CONNECTION_ERROR | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoConnectionErrorHandler:Function = function( event:StudioVideoEvent):void { trace("Error connecting to video."); }; videoComponentInstance.addEventListener( StudioVideoEvent.CONNECTION_ERROR, videoConnectionErrorHandler); |
FAIL | com.google.ads.studio.events.StudioEvent | Dispatched when the component has failed to initialize. |
FIRST_QUARTILE | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoFirstQuartileHandler:Function = function( event:StudioVideoEvent):void { trace("Video has reached first quartile."); }; videoComponentInstance.addEventListener( StudioVideoEvent.FIRST_QUARTILE, videoFirstQuartileHandler); |
INIT | com.google.ads.studio.events.StudioEvent | Dispatched when the component has initialized.
This event may fire almost immediately after component construction. To
ensure capturing the initialized state please refer to the example:
// Note the variable component refers to the component instance. import com.google.ads.studio.events.StudioEvent; var initializedHandler:Function = function( event:StudioEvent = null):void { trace("The component initialized!"); }; if (component.isInitialized()) { initializedHandler(); } else { component.addEventListener(StudioEvent.INIT, initializedHandler); } |
MID_POINT | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoMidpointHandler:Function = function( event:StudioVideoEvent):void { trace("Video has reached midpoint."); }; videoComponentInstance.addEventListener( StudioVideoEvent.MID_POINT, videoMidpointHandler); |
MUTE | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoMuteHandler:Function = function(event:StudioVideoEvent):void { trace("Video mutes."); }; videoComponentInstance.addEventListener( StudioVideoEvent.MUTE, videoMuteHandler); |
NETSTREAM_BUFFER_EMPTY | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var netStreamBufferEmptyHandler:Function = function( event:StudioVideoEvent):void { trace("Net stream buffer is empty."); }; videoComponentInstance.addEventListener( StudioVideoEvent.NETSTREAM_BUFFER_EMPTY, netStreamBufferEmptyHandler); |
NETSTREAM_BUFFER_FULL | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var netStreamBufferFullHandler:Function = function( event:StudioVideoEvent):void { trace("Net stream buffer is full."); }; videoComponentInstance.addEventListener( StudioVideoEvent.NETSTREAM_BUFFER_FULL, netStreamBufferFullHandler); |
NETSTREAM_PLAY_START | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var netStreamPlayStartHandler:Function = function( event:StudioVideoEvent):void { trace("Net stream starts playing."); }; videoComponentInstance.addEventListener( StudioVideoEvent.NETSTREAM_PLAY_START, netStreamPlayStartHandler); |
NETSTREAM_PLAY_STREAMNOTFOUND | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var netStreamNotFoundHandler:Function = function( event:StudioVideoEvent):void { trace("Can't find net stream."); }; videoComponentInstance.addEventListener( StudioVideoEvent.NETSTREAM_PLAY_STREAMNOTFOUND, netStreamNotFoundHandler); |
NET_CONNECTION_AVAILABLE | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var netConnectionAvailableHandler:Function = function( event:StudioVideoEvent):void { trace("Net connection is available."); }; videoComponentInstance.addEventListener( StudioVideoEvent.NET_CONNECTION_AVAILABLE, netConnectionAvailableHandler); |
NET_CONNECTION_PREINITIALIZE | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var netConnectionPreinitializeHandler:Function = function( event:StudioVideoEvent):void { trace("Net connection is pre-initialized."); }; videoComponentInstance.addEventListener( StudioVideoEvent.NET_CONNECTION_PREINITIALIZE, netConnectionPreinitializeHandler); |
NET_CONNECTION_STATUS | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var netConnectionStatusHandler:Function = function( event:StudioVideoEvent):void { trace("Net connection status code is " + event.info.code + "."); }; videoComponentInstance.addEventListener( StudioVideoEvent.NET_CONNECTION_STATUS, netConnectionStatusHandler); |
NET_STREAM_AVAILABLE | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var netStreamAvailableHandler:Function = function( event:StudioVideoEvent):void { trace("Net stream is available."); }; videoComponentInstance.addEventListener( StudioVideoEvent.NET_STREAM_AVAILABLE, netStreamAvailableHandler); |
NET_STREAM_CUE_POINT | com.google.ads.studio.events.StudioVideoEvent | |
NET_STREAM_META_DATA | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var netStreamMetaHandler:Function = function( event:StudioVideoEvent):void { trace("Net Stream Meta Data width is " + event.info.width + ", and height is " + event.info.height + "."); }; videoComponentInstance.addEventListener( StudioVideoEvent.NET_STREAM_META_DATA, netStreamMetaHandler); |
NET_STREAM_PREINITIALIZE | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var netStreamPreInitializeHandler:Function = function( event:StudioVideoEvent):void { trace("Net stream is pre-initialized."); }; videoComponentInstance.addEventListener( StudioVideoEvent.NET_STREAM_PREINITIALIZE, netStreamPreInitializeHandler); |
NET_STREAM_STATUS | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var netStreamStatusHandler:Function = function( event:StudioVideoEvent):void { trace("Net stream status code is " + event.info.code + "."); }; videoComponentInstance.addEventListener( StudioVideoEvent.NET_STREAM_STATUS, netStreamStatusHandler); |
PAUSE | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoPauseHandler:Function = function(event:StudioVideoEvent):void { trace("Video pauses."); }; videoComponentInstance.addEventListener( StudioVideoEvent.PAUSE, videoPauseHandler); |
PLAY | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoPlayHandler:Function = function(event:StudioVideoEvent):void { trace("Video plays."); }; videoComponentInstance.addEventListener( StudioVideoEvent.PLAY, videoPlayHandler); |
REPLAY | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoReplayHandler:Function = function(event:StudioVideoEvent):void { trace("Video replays."); }; videoComponentInstance.addEventListener( StudioVideoEvent.REPLAY, videoReplayHandler); |
STATE_CHANGE | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoStateChangeHandler:Function = function( event:StudioVideoEvent):void { trace("Video state has changed."); }; videoComponentInstance.addEventListener( StudioVideoEvent.STATE_CHANGE, videoStateChangeHandler); |
STOP | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoStopHandler:Function = function(event:StudioVideoEvent):void { trace("Video stops."); }; videoComponentInstance.addEventListener( StudioVideoEvent.STOP, videoStopHandler); |
THIRD_QUARTILE | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoThirdQuartileHandler:Function = function( event:StudioVideoEvent):void { trace("Video has reached third quartile."); }; videoComponentInstance.addEventListener( StudioVideoEvent.THIRD_QUARTILE, videoThirdQuartileHandler); |
UN_MUTE | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoUnmuteHandler:Function = function(event:StudioVideoEvent):void { trace("Video unmutes."); }; videoComponentInstance.addEventListener( StudioVideoEvent.UN_MUTE, videoUnmuteHandler); |
Constructors
VideoPlayer(registeredByConfigurable:Boolean=false)
:
void
Constructs a video player.
Instance Methods
Defined in: com.google.ads.studio:EnabledComponent
getEnabler()
:
Object
isInitialized()
:
Boolean
Returns whether the component has initialized.
Defined in com.google.ads.studio.video:VideoPlayer
getCurrentVideoController()
:
VideoController
Gets a reference to the video controller.
import com.google.ads.studio.video.VideoController; // Get a reference to the current video. var videoController:VideoController = videoComponentInstance.getCurrentVideoController();
getElapsedSeconds()
:
Number
Returns the elapsed time in seconds of the current video controller.
getPercentLoaded()
:
Number
Indicates the percent of video loaded in the current video controller as a number between 0 and 1.
Note: Because streaming videos will only cache the number of seconds stated in the buffer length, it's more accurate for the user to believe that the entire video is loaded as they can seek to the non-cached portion of the video. Thus, this method will return 100% if the video is streaming. Also, if the content length header is missing from the HTTP response, bytesTotal will always be 0 so we assume the entire video has loaded and report 100%.
getReportingIdentifier()
:
String
Returns the reporting identifier.
getTotalSeconds()
:
Number
Returns the total duration in seconds of the current video. In order to
get this value, you must wait for the
StudioVideoEvent.DURATION
event.
getVideoObject()
:
Video
Gets the video object.
import com.google.ads.studio.video.VideoController; import com.google.ads.studio.events.StudioVideoEvent; // Get a reference to the current video. var videoController:VideoController = videoComponentInstance.getCurrentVideoController(); var videoBufferedHandler:Function = function( event:StudioVideoEvent):void { var videoObject:Video = videoController.getVideoObject(); }; videoComponentInstance.addEventListener( StudioVideoEvent.BUFFERED, videoBufferedHandler);
isVideoMuted()
:
Boolean
Indicates whether the current video controller is muted.
isVideoPaused()
:
Boolean
Indicates whether the current video controller is paused.
isVideoPlaying()
:
Boolean
Returns whether the current video controller is playing.
isVideoStopped()
:
Boolean
Indicates whether the current video controller is stopped or complete.
mute()
:
void
Mutes the current video controller.
pause(alwaysPause:Boolean=false)
:
void
Pauses the current video controller.
play()
:
void
Plays the current video controller.
seek(time:Number)
:
void
Seeks the playhead to a particular time in seconds.
setCloseOnComplete(closeOnComplete:Boolean)
:
void
Sets whether the creative should close on completion of the video.
setPrimary(primary:Boolean)
:
void
Sets whether this video player is the primary video player. Only one video player should ever have this option enabled at one time.
setReportDuration(reportDuration:Boolean)
:
void
Sets whether this video player should report its duration as the VPAID duration. The option only takes affect if the video player is also the primary video player.
stop()
:
void
Stops the current video controller.
unload()
:
void
Unloads the player and preps it for garbage collection as well as possible.
import com.google.ads.studio.video.VideoController; // Get a reference to the current video. var videoController:VideoController = videoComponentInstance.getCurrentVideoController(); var endFrameClickHandler:Function = function(event:MouseEvent):void { videoController.unload(); }; endFrameButton.addEventListener(MouseEvent.CLICK, endFrameClickHandler);
unmute()
:
void
Unmutes the current video controller.