Video Player Advanced component that enables the user to play one or more videos that get tracked. This component is a wrapper for the Playlist class that offers settings that can be managed in DART.
For more information, see Video Player Advanced.
The following diagram details the Video Player Advanced architecture:

import com.google.ads.studio.HtmlEnabler; import com.google.ads.studio.events.StudioEvent; 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); }); function setCurrentVideoLabel():void { videoNumberTxt.text = (videoPlayer.getCurrentVideoIndex() + 1) + " / " + videoPlayer.getNumberOfVideos(); } videoPlayer.addEventListener( StudioEvent.INIT, function (event:StudioEvent):void { // Gets dispatched after component has read its properties // and created videos entries. setCurrentVideoLabel(); }); videoPlayer.addEventListener( StudioEvent.UPDATE, function (event:StudioEvent):void { // Gets dispatched when video is changed. setCurrentVideoLabel(); }); previousBtn.addEventListener( MouseEvent.CLICK, function (event:MouseEvent):void { videoPlayer.previous(); }); nextBtn.addEventListener( MouseEvent.CLICK, function (event:MouseEvent):void { videoPlayer.next(); });
Advanced Usage:
// Make sure the video player is set to wait for command. import com.google.ads.studio.video.EnhancedVideoController; // Get a reference to the current video. var videoController:EnhancedVideoController = videoPlayer.getCurrentVideoController(); // Set the reporting identifier. videoController.setReportingIdentifier("new identifier"); // Drill down to the first set of URL entries and set the high URL. videoController.getVideoEntries()[0].setHigh("newVideo.flv"); // Kick off and start playing. videoPlayer.getPlaylist().start(true); // trackAsAutoPlay
import com.google.ads.studio.video.EnhancedVideoController; import com.google.ads.studio.video.VideoEntry; // Create the new video item. var videoController:EnhancedVideoController = new EnhancedVideoController(); // Set the reporting identifier. videoController.setReportingIdentifier("new identifier"); // Create a set of URL entries. var videoEntry:VideoEntry = new VideoEntry("high.flv", "mid.flv", "low.flv"); // Attach the URL entries to the video item. videoController.addVideoEntry(videoEntry); // Add the video item to the end of the playlist. videoPlayer.getPlaylist().addVideoController(videoController); // Start the playlist. videoPlayer.getPlaylist().start(true); // trackAsAutoPlay
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); | ||||
BUFFERED | com.google.ads.studio.events.StudioVideoEvent |
import com.google.ads.studio.events.StudioVideoEvent; var videoBufferedHandler:Function = function(event:StudioVideoEvent):void { trace("Video has buffered."); }; videoComponentInstance.addEventListener( StudioVideoEvent.BUFFERED, videoBufferedHandler); | ||||
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); | ||||
UPDATE | com.google.ads.studio.events.StudioEvent | Dispatched when a new VideoController is being played. The properties of the event object have the following values:
import com.google.ads.studio.events.StudioEvent; var videoUpdateHandler:Function = function(event:StudioEvent):void { trace("Video controller has changed."); }; videoComponentInstance.addEventListener( StudioEvent.UPDATE, videoUpdateHandler); |
Constructors
VideoPlayerAdvanced()
:
void
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:VideoPlayerAdvanced
getCurrentVideoController()
:
EnhancedVideoController
Gets the current playing video controller.
getCurrentVideoIndex()
:
int
Gets the index of the current playing VideoController.
getElapsedSeconds()
:
Number
Returns the elapsed time in seconds of the current video controller.
getNumberOfVideos()
:
int
Gets the number of VideoControllers that have been added to the playlist.
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%.
getPlaylist()
:
Playlist
Gets the playlist object.
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.
isVideoMuted()
:
Boolean
Indicates whether the current video controller is muted.
isVideoPaused()
:
Boolean
Indicates whether the current video controller is paused.
isVideoPlaying()
:
Boolean
Indicates 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.
next()
:
EnhancedVideoController
Goes to the next video (EnhancedVideoController) in the playlist or back to the first if the current video is the last in the playlist.
pause(alwaysPause:Boolean=false)
:
void
Pauses the current video controller.
play()
:
void
Plays the current video controller.
previous()
:
EnhancedVideoController
Goes to the previous video (EnhancedVideoController) in the playlist or to the last if the current video is the first in the playlist.
seek(time:Number)
:
void
Seeks the playhead to a particular time in seconds.
setCloseOnComplete(closeOnComplete:Boolean)
:
void
Sets whether the creative should close after a video in this VideoPlayer completes.
setPlaylist(playlist:
Playlist)
:
void
Sets the playlist object.
setPrimary(primary:Boolean)
:
void
Sets whether the videos in this VideoPlayer should be the primary videos.
setReportDuration(reportDuration:Boolean)
:
void
Sets whether the videos in this VideoPlayer should report their durations as the VPAID durations.
skipTo(index:int)
:
EnhancedVideoController
Skips directly to the index of one of the VideoControllers and starts playing it.
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.EnhancedVideoController; // Get a reference to the current video. var videoController:EnhancedVideoController = videoComponentInstance.getCurrentVideoController(); var endFrameClickHandler:Function = function(event:MouseEvent):void { videoController.unload(); }; endFrameButton.addEventListener(MouseEvent.CLICK, endFrameClickHandler);
unmute()
:
void
Unmutes the current video controller.