An enhanced video controller. This controller provides additional helper methods as well as the ability to smart buffer a video before playing it. As we expose the checkPolicyFile attribute of the NetStream attribute, this class only supports Flash Player 9; if this functionality is not required the minimum compatible Flash player version is 7.
Constants
| Name | Value | Description |
|---|---|---|
VIDEO_COMPLETE_HIDE_VIDEO | videoCompleteHideVideo | Hide the video when it has completed. |
VIDEO_COMPLETE_SHOW_FIRST_FRAME | videoCompleteShowFirstFrame | Stay on the first frame of the video when it has completed. |
VIDEO_COMPLETE_SHOW_LAST_FRAME | videoCompleteShowLastFrame | Stay on the last frame of the video when it has completed. |
Events
| Name | Type | Description |
|---|---|---|
BACKWARDS_SEEK | com.google.ads.studio.events.StudioVideoEvent | |
BUFFERED | com.google.ads.studio.events.StudioVideoEvent | |
COMPLETE | com.google.ads.studio.events.StudioVideoEvent | |
CONNECTION_ERROR | com.google.ads.studio.events.StudioVideoEvent | |
FIRST_QUARTILE | com.google.ads.studio.events.StudioVideoEvent | |
MID_POINT | com.google.ads.studio.events.StudioVideoEvent | |
MUTE | com.google.ads.studio.events.StudioVideoEvent | |
NETSTREAM_BUFFER_EMPTY | com.google.ads.studio.events.StudioVideoEvent | |
NETSTREAM_BUFFER_FULL | com.google.ads.studio.events.StudioVideoEvent | |
NETSTREAM_PLAY_START | com.google.ads.studio.events.StudioVideoEvent | |
NETSTREAM_PLAY_STREAMNOTFOUND | com.google.ads.studio.events.StudioVideoEvent | |
NET_CONNECTION_AVAILABLE | com.google.ads.studio.events.StudioVideoEvent | |
NET_CONNECTION_PREINITIALIZE | com.google.ads.studio.events.StudioVideoEvent | |
NET_CONNECTION_STATUS | com.google.ads.studio.events.StudioVideoEvent | |
NET_STREAM_AVAILABLE | com.google.ads.studio.events.StudioVideoEvent | |
NET_STREAM_CUE_POINT | com.google.ads.studio.events.StudioVideoEvent | |
NET_STREAM_META_DATA | com.google.ads.studio.events.StudioVideoEvent | |
NET_STREAM_PREINITIALIZE | com.google.ads.studio.events.StudioVideoEvent | |
NET_STREAM_STATUS | com.google.ads.studio.events.StudioVideoEvent | |
PAUSE | com.google.ads.studio.events.StudioVideoEvent | |
PLAY | com.google.ads.studio.events.StudioVideoEvent | |
PLAYHEAD_MOVE | com.google.ads.studio.events.StudioVideoEvent | |
REPLAY | com.google.ads.studio.events.StudioVideoEvent | |
STATE_CHANGE | com.google.ads.studio.events.StudioVideoEvent | |
STOP | com.google.ads.studio.events.StudioVideoEvent | |
THIRD_QUARTILE | com.google.ads.studio.events.StudioVideoEvent | |
UN_MUTE | com.google.ads.studio.events.StudioVideoEvent |
Constructors
EnhancedVideoController()Creates an EnhancedVideoController.
Instance Methods
Defined in: com.google.ads.studio.video:VideoController
addVideoEntry(videoEntry:
VideoEntry)
:
void
Add a video entry to the video controller. The order in which these are
added is the order in which they'll be attempted. The first video
entry is pre-created and can either be added (which replaces the first
dummy) or edited via getVideoEntries()[0].setHigh("foo.flv");
.
These example code blocks are equivalent.
import com.google.ads.studio.video.SmartStreamingConnection;
import com.google.ads.studio.video.VideoController;
import com.google.ads.studio.video.VideoEntry;
var videoController:VideoController = new VideoController();
videoController.setReportingIdentifier("my video");
videoController.addVideoEntry(new VideoEntry(
"streaming_high.flv",
null, null,
SmartStreamingConnection));
videoController.addVideoEntry(new VideoEntry("progressive_high.flv"));
import com.google.ads.studio.video.SmartStreamingConnection;
import com.google.ads.studio.video.VideoController;
import com.google.ads.studio.video.VideoEntry;
var videoController:VideoController = new VideoController();
videoController.setReportingIdentifier("my video");
videoController.getVideoEntries()[0].setHigh("streaming_high.flv");
videoController.getVideoEntries()[0].setConnectionType(
SmartStreamingConnection);
// Secondary video entries always needs to be added.
videoController.addVideoEntry(new VideoEntry("progressive_high.flv"));
attachAudioAndVideo()
:
voidAfter the netstream object is available, this attaches the video and audio to netstream object.
cloneWithBasicProperties()
:
VideoControllerClones a video controller with its basic properties such as buffer time and reporting ID. Note that this does NOT copy any video entries or any other properties.
executeStateCommands()
:
voidgetAudioChannel()
:
AudioChannelGets the audio channel.
import com.google.ads.studio.audio.AudioChannel;
var unmuteClickHandler:Function = function(event:MouseEvent):void {
var audioChannel:AudioChannel = videoComponentInstance.
getCurrentVideoController().getAudioChannel();
audioChannel.MAX_VOLUME;
};
unmuteButton.addEventListener(MouseEvent.CLICK, unmuteClickHandler);
getBufferTime()
:
NumberGets the set buffer time.
import com.google.ads.studio.video.VideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:VideoController =
videoComponentInstance.getCurrentVideoController();
var videoBufferedHandler:Function = function(
event:StudioVideoEvent):void {
trace("Video's buffer time is " +
videoController.getBufferTime() + ".");
};
videoComponentInstance.addEventListener(
StudioVideoEvent.BUFFERED,
videoBufferedHandler);
getNetConnection()
:
NetConnectionGets the current netconnection.
import com.google.ads.studio.video.VideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:VideoController =
videoComponentInstance.getCurrentVideoController();
var netConnectionAvailableHandler:Function = function(
event:StudioVideoEvent):void {
trace("Current Net Connection is " +
videoController.getNetConnection() + ".");
};
videoController.addEventListener(
StudioVideoEvent.NET_CONNECTION_AVAILABLE,
netConnectionAvailableHandler);
getNetStream()
:
NetStreamGets current the netstream object.
import com.google.ads.studio.video.VideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:VideoController =
videoComponentInstance.getCurrentVideoController();
var onNetStreamAvailableHandler:Function = function(
event:StudioVideoEvent):void {
trace("Current Net Stream object is " +
videoController.getNetStream() + ".");
};
videoController.addEventListener(
StudioVideoEvent.NET_STREAM_AVAILABLE,
netStreamAvailableHandler);
getNumberOfVideoEntries()
:
NumberGets the number of video entries.
import com.google.ads.studio.video.VideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:VideoController =
videoComponentInstance.getCurrentVideoController();
var videoBufferedHandler:Function = function(
event:StudioVideoEvent):void {
trace("The number of video entry(ies) is(are) " +
videoController.getNumberOfVideoEntries() + ".");
};
videoComponentInstance.addEventListener(
StudioVideoEvent.BUFFERED,
videoBufferedHandler);
getPlayerState()
:
AbstractPlayerStateGets the current player state.
import com.google.ads.studio.video.VideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:VideoController =
videoComponentInstance.getCurrentVideoController();
var enterFrameHandler:Function = function(event:Event):void {
trace("The current player state is " +
videoController.getPlayerState() + ".");
};
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
getReportingIdentifier()
:
StringGets the video reporting identifier.
import com.google.ads.studio.video.VideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:VideoController =
videoComponentInstance.getCurrentVideoController();
var videoBufferedHandler:Function = function(
event:StudioVideoEvent):void {
trace("The video reporting identifier is " +
videoController.getReportingIdentifier() + ".");
};
videoComponentInstance.addEventListener(
StudioVideoEvent.BUFFERED,
videoBufferedHandler);
getVideoConnection()
:
AbstractVideoConnectionGets the current video connection.
import com.google.ads.studio.video.VideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:VideoController =
videoComponentInstance.getCurrentVideoController();
var videoBufferedHandler:Function = function(
event:StudioVideoEvent):void {
trace("The current Video connection is " +
videoController.getVideoConnection() + ".");
};
videoComponentInstance.addEventListener(
StudioVideoEvent.BUFFERED,
videoBufferedHandler);
getVideoEntries()
:
ArrayGets the currently added video entries.
import com.google.ads.studio.video.VideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:VideoController =
videoComponentInstance.getCurrentVideoController();
var videoBufferedHandler:Function = function(
event:StudioVideoEvent):void {
var videoEntries:Array = videoController.getVideoEntries();
for (var i = 0; i < videoEntries.length; i++) {
trace("Video Entry #" + i + "is " + videoEntries[i]);
}
};
videoComponentInstance.addEventListener(
StudioVideoEvent.BUFFERED,
videoBufferedHandler);
getVideoObject()
:
VideoGets 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);
mute()
:
voidMutes the audio channel associated to the playing video.
var muteClickHandler:Function = function(event:MouseEvent):void {
videoController.mute();
};
muteButton.addEventListener(MouseEvent.CLICK, muteClickHandler);
pause(alwaysPause:Boolean=false)
:
voidPauses the video.
var pauseClickHandler:Function = function(event:MouseEvent):void {
videoController.pause();
};
pauseButton.addEventListener(MouseEvent.CLICK, pauseClickHandler);
play(trackAsAutoPlay:Boolean=false)
:
voidPlays the video.
var playClickHandler:Function = function(event:MouseEvent):void {
videoController.play();
};
playButton.addEventListener(MouseEvent.CLICK, playClickHandler);
replay()
:
voidReplays the video.
var replayClickHandler:Function = function(event:MouseEvent):void {
videoController.replay();
};
replayButton.addEventListener(MouseEvent.CLICK, replayClickHandler);
seek(time:Number)
:
voidSeeks the playhead to a particular time in seconds.
var seekClickHandler:Function = function(event:MouseEvent):void {
videoController.seek(10);
};
seekButton.addEventListener(MouseEvent.CLICK, seekClickHandler);
setBufferTime(seconds:Number)
:
voidSets the amount of time to buffer.
var timeInSeconds:int = 1;
videoController.setBufferTime(timeInSeconds);
setCloseOnComplete(closeOnComplete:Boolean)
:
voidSets whether the creative should close on completion of this video.
setEnabler(enabler:Object)
:
voidSets the Enabler.
setPrimary(isPrimary:Boolean)
:
voidSets whether this is the primary video controller.
setReportDuration(reportDuration:Boolean)
:
voidSets whether this controller should report its duration.
setReportingIdentifier(reportingIdentifier:String)
:
voidSets the reporting identifier for the videos to report as.
videoController.setReportingIdentifier("Video_1");
setVideoObject(video:flash.media:Video)
:
voidSets the video object to display the video.
import com.google.ads.studio.video.VideoController;
import com.google.ads.studio.video.VideoEntry;
var videoController:VideoController =
videoComponentInstance.getCurrentVideoController();
var addVideoClickHandler:Function = function(event:MouseEvent):void {
var videoEntry:VideoEntry =
new VideoEntry("broadband_video.flv", "midband_video.flv",
"narrowband_video.flv");
videoController = new VideoController();
videoController.setReportingIdentifier("new_video");
videoController.addVideoEntry(videoEntry);
videoController.setVideoObject(vidPlayerInstance.getVideoObject());
videoController.play();
};
addVideoButton.addEventListener(MouseEvent.CLICK, addVideoClickHandler);
stop()
:
voidStops the video. The current implementation for stop is to pause and seek the playhead to 0.
var stopClickHandler:Function = function(event:MouseEvent):void {
videoController.stop();
};
stopButton.addEventListener(MouseEvent.CLICK, stopClickHandler);
unload()
:
voidUnloads the video controller and preps it for garbage collection as well as possible.
var unloadClickHandler:Function = function(event:MouseEvent):void {
videoController.unload();
};
unloadButton.addEventListener(MouseEvent.CLICK, unloadClickHandler);
unmute()
:
voidUnmutes the audio channel associated to the playing video.
var unmuteClickHandler:Function = function(event:MouseEvent):void {
videoController.unmute();
unmuteButton.addEventListener(MouseEvent.CLICK, unmuteClickHandler);
Defined in com.google.ads.studio.video:EnhancedVideoController
addAllEventsListener(handler:Function)
:
voidConvenience method that adds a handler to all video events.
buffer(playAfterBuffer:Boolean=false, trackAsAutoPlay:Boolean=false)
:
voidBuffers the video and optionally plays it after buffering. This method can only be called when the player is in an idle state.
import com.google.ads.studio.video.EnhancedVideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:EnhancedVideoController =
videoComponentInstance.getCurrentVideoController();
var videoComponentInitHandler:Function = function(
event:StudioEvent):void {
videoController.buffer(true);
};
videoComponentInstance.addEventListener(
StudioEvent.INIT,
videoComponentInitHandler);
getDuration()
:
NumberGets the duration of the current video.
import com.google.ads.studio.video.EnhancedVideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:EnhancedVideoController =
videoComponentInstance.getCurrentVideoController();
var videoBufferedHandler:Function = function(
event:StudioVideoEvent):void {
trace("Current video's duration is " +
videoController.getDuration() + ".");
};
videoComponentInstance.addEventListener(
StudioVideoEvent.BUFFERED,
videoBufferedHandler);
getElapsed()
:
NumberThe elapsed seconds of the video.
import com.google.ads.studio.video.EnhancedVideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:EnhancedVideoController =
videoComponentInstance.getCurrentVideoController();
var videoPlayHandler:Function = function(event:StudioVideoEvent):void {
trace("Video's elapsed seconds is " +
videoController.getElapsed() + ".");
};
videoController.addEventListener(
StudioVideoEvent.PLAY,
videoPlayHandler);
getPercentLoaded()
:
NumberGets the percent the video has loaded. Note: If the content-length header is missing from the FLV this method returns the playhead time and the amount of video buffered over the duration of the video.
import com.google.ads.studio.video.EnhancedVideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:EnhancedVideoController =
videoComponentInstance.getCurrentVideoController();
var trackPercentLoaded:Function = function(event:Event):void {
trace("Video's percent loaded is " +
videoComponentInstance.getPercentLoaded() + "%.");
};
var videoBufferedHandler:Function = function(
event:StudioVideoEvent):void {
this.addEventListener(Event.ENTER_FRAME, trackPercentLoaded);
};
videoComponentInstance.addEventListener(
StudioVideoEvent.BUFFERED,
videoBufferedHandler);
getVolume()
:
NumberThe volume of the audio.
import com.google.ads.studio.video.EnhancedVideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:EnhancedVideoController =
videoComponentInstance.getCurrentVideoController();
var videoBufferedHandler:Function = function(
event:StudioVideoEvent):void {
trace("Audio's volume is " + videoController.getVolume() + ".");
};
videoComponentInstance.addEventListener(
StudioVideoEvent.BUFFERED,
videoBufferedHandler);
isCurrentVideoConnectionHttp()
:
BooleanIndicates whether the current video connection is over HTTP.
import com.google.ads.studio.video.EnhancedVideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:EnhancedVideoController =
videoComponentInstance.getCurrentVideoController();
var videoBufferedHandler:Function = function(
event:StudioVideoEvent):void {
if (videoController.isCurrentVideoConnectionHttp()) {
trace("Current video connection is Http.");
}
};
videoComponentInstance.addEventListener(
StudioVideoEvent.BUFFERED,
videoBufferedHandler);
play(trackAsAutoPlay:Boolean=false)
:
voidPlays the video.
var playClickHandler:Function = function(event:MouseEvent):void {
videoController.play();
};
playButton.addEventListener(MouseEvent.CLICK, playClickHandler);
removeAllEventsListener(handler:Function)
:
voidConvenience method that removes a handler to all video events.
setCheckPolicyFile(checkPolicyFile:Boolean)
:
voidSets whether to check the policy file when connecting to a video. This allows the user to capture BitmapDatas of videos on a different domain from the SWF's if the crossdomain policy file allows.
import com.google.ads.studio.video.EnhancedVideoController;
var videoController:EnhancedVideoController =
videoComponentInstance.getCurrentVideoController();
videoController.setCheckPolicyFile(true);
setPostBufferCallback(callback:Function)
:
voidConvenience method to add a callback to invoke when the video has finished buffering.
import com.google.ads.studio.video.EnhancedVideoController;
var videoController:EnhancedVideoController =
videoComponentInstance.getCurrentVideoController();
var bufferCallBack:Function = function():void {
trace("Video has buffered.");
};
videoController.setPostBufferCallback(bufferCallBack);
setVideoCompleteCallback(callback:Function)
:
voidSets the callback to invoke when the video has completed.
import com.google.ads.studio.video.EnhancedVideoController;
var videoController:EnhancedVideoController =
videoComponentInstance.getCurrentVideoController();
var videoCompleteCallBack:Function = function():void {
trace("Video has completed playing.");
};
videoController.setVideoCompleteCallback(videoCompleteCallBack);
setVideoCompleteDisplay(option:String)
:
void
Sets what to display when the video has completed. The options are:
EnhancedVideoController.VIDEO_COMPLETE_SHOW_LAST_FRAME,
EnhancedVideoController.VIDEO_COMPLETE_SHOW_FIRST_FRAME, or
EnhancedVideoController.VIDEO_COMPLETE_HIDE_VIDEO. The
default setting is
EnhancedVideoController.VIDEO_COMPLETE_HIDE_VIDEO.
import com.google.ads.studio.video.EnhancedVideoController;
import com.google.ads.studio.events.StudioVideoEvent;
var videoController:EnhancedVideoController =
videoComponentInstance.getCurrentVideoController();
var videoBufferedHandler:Function = function(
event:StudioVideoEvent):Void {
videoController.setVideoCompleteDisplay(
EnhancedVideoController.VIDEO_COMPLETE_SHOW_FIRST_FRAME);
// For other Video complete display options:
// videoController.setVideoCompleteDisplay(
// EnhancedVideoController.VIDEO_COMPLETE_SHOW_LAST_FRAME);
// videoController.setVideoCompleteDisplay(
// EnhancedVideoController.VIDEO_COMPLETE_HIDE_VIDEO);
};
videoComponentInstance.addEventListener(
StudioVideoEvent.BUFFERED,
videoBufferedHandler);
setVolume(volume:Number)
:
voidSets the volume of this video.
import com.google.ads.studio.video.EnhancedVideoController;
var videoController:EnhancedVideoController =
videoComponentInstance.getCurrentVideoController();
var volume:Number = 0;
var volumeDownClickHandler:Function = function(event:MouseEvent):void {
volume = Math.max(0, volume - .1);
videoController.setVolume(volume);
};
volumeDownButton.addEventListener(
MouseEvent.CLICK,
volumeDownClickHandler);
var volumeUpClickHandler:Function = function(event:MouseEvent):void {
volume = Math.min(1, volume + .1);
videoController.setVolume(volume);
};
volumeUpButton.addEventListener(MouseEvent.CLICK, volumeUpClickHandler);