xm.components.FLVDisplayComponent
- Class:
- xm.components.FLVDisplayComponent
- Inheritance:
- MovieClip > xm.corpus.resizableComponent > xm.components.FLVDisplayComponent
- Edition:
- Flash 8
- Language Version:
- ActionScript 2.0
- Player Version:
- Flash Player 8
Methods
play(Void) : Void
Opens and begins playback of the video file specified by the url property.
if (myToobPlayer.autoPlay) {
// start playing the video
myToobPlayer.url = "clip.flv";
}
else {
// url property is delayed during the component initialization,
// and because of this, myToobPlayer.display.play() will not be able to
// work properly, if we do not wait a frame for the component to
// fully initialize
onEnterFrame = function() {
myToobPlayer.url = "clip.flv";
myToobPlayer.display.play();
delete onEnterFrame;
}
}
// or simpler
myToobPlayer.autoPlay = true;
myToobPlayer.url = "clip.flv";
pause([p_pause:Boolean]) : Void
Pauses or resumes playback of a stream. If the p_pause parameter is not specified, pause acts as a toggle.
pause_button.onRelease = function() {
myToobPlayer.display.pause();
}
stop(Void) : Void
Stops playing the video, closes the stream, and sets the time property to 0.
myToobPlayer.display.stop();
clear(Void) : Void
Stops playing the video (same as the stop method), and clears the image currently displayed in the video object.
clear_button.onRelease = function() {
// clear the video, so that the preview image underneath becomes visible
myToobPlayer.display.clear();
myToobPlayer.image.url = "previewImage.jpg";
}
Methods inherited from the resizableClip class
setSize(p_width:Number, p_height:Number) : Void
Resizes the component to the requested size. (Dimensions are always rounded.)
addEventListener(p_eventName:String, p_handler) : Void
Registers a listener object or function (p_handler) with a component instance that is broadcasting an event. When the event occurs, the listener object or function is notified. If p_handler is a function, it will be invoked from within the dispatching object's scope.
Example 1
myToobPlayer.addEventListener("complete", this);
function complete(e:Object):Void {
if (myToobPlayer.display.playing) {
// finished playing current video; play next video
myToobPlayer.url = nextClip;
}
}
Example 2
myToobPlayer.display.addEventListener("complete", myCompleteHandler);
function myCompleteHandler(e:Object):Void {
if (myToobPlayer.display.playing) {
// finished playing current video; play next video
myToobPlayer.url = nextClip;
}
}
addEventListenerL(p_eventName:String, p_obj:Object, p_handler) : Void
Registers a listener function (p_handler) with a component instance that is broadcasting an event. When the event occurs, the listener function is invoked using the p_obj scope.
Example
myToobPlayer.display.addEventListenerL("complete", this, "myCompleteHandler");
myToobPlayer.display.addEventListenerL("complete", myToobPlayer, function() { trace("Finished playing: "+this.url); });
function myCompleteHandler(e:Object):Void {
if (myToobPlayer.display.playing) {
// finished playing current video; play next video
myToobPlayer.url = nextClip;
}
}
removeEventListener(p_eventName:String, p_handler) : Void
Unregisters a listener.
Example 1
myToobPlayer.display.removeEventListener("complete", this);
Example 2
myToobPlayer.display.removeEventListener("complete", myCompleteHandler);
removeEventListenerL(p_eventName:String, p_obj:Object, p_handler) : Void
Unregisters a listener.
Example
myToobPlayer.display.removeEventListener("complete", this, "myCompleteHandler");
removeAllEventListeners(p_eventName:String) : Void
Unregisters all listeners registered with a p_eventName event.
Example
myToobPlayer.display.removeAllEventListeners("complete");
dispatchEvent(p_eventObj:Object) : Void
Dispatches an event to any listener registered with an instance of the class. This method is usually called from within a component's class file. p_eventObj is passed to all listeners, and must contain a type property indicating the name of the event.
Example
// trigger a custom event
myToobPlayer.display.dispatchEvent({ type: "myCustomEvent"});
Properties
url : String
Specifies an FLV file to play. If autoPlay property is set to true, playback will start immediately. Otherwise, use play method to start the playback programmatically.
xm.components.ToobPlayerComponent.url is a wrapper for this property, and implements additional mechanisms for loading YouTube videos.
autoPlay : Boolean
If set to true, causes the FLV file to play immediately when the url property is set. The default value is true. xm.components.ToobPlayerComponent.autoPlay property is an alias for this property.
Example
// do not auto-play the video myToobPlayer.autoPlay = false; // load preview image from YouTube myToobPlayer.autoLoadYouTubePreviewImage = "YouTube"; myToobPlayer.url = "http://www.youtube.com/watch?v=T8oRFcA0mFM";
autoRepeat : Boolean
If set to true, causes the FLV file to play continuously, i.e. to start over each time upon reaching its end. The default value is false. xm.components.ToobPlayerComponent.autoRepeat property is an alias for this property.
Example
myToobPlayer.autoRepeat = true;
volume : Number
Indicates the volume control setting. The default value is 50. xm.components.ToobPlayerComponent.volume property is an alias for this property.
Example
// mute myToobPlayer.volume = 0;
zoom : Number
Indicates the magnification of the video. The default value is 100. This property is only applicable for the resizeMode set to rmCenter.
Example
import xm.components.FLVDisplay; myToobPlayer.display.resizeMode = rmCenter; myToobPlayer.display.zoom = 150;
resizeMode : String
Defines how to fit the video into the component area. The following resize modes are available:
- static rmFitIntoAR : String
- "fit into component area / mind aspect ratio"
- static rmFitInto : String
- "fit into component area"
- static rmFillOut : String
- "fill out component area"
- static rmCenter : String
- "center in component area"
- static rmCenterOrFitInto : String
- "center in component area / shrink if necessary"
- static rmComponentToVideo : String
- "resize component to video size"
The default value is rmFitIntoAR.
Example
// resizes the video proportionally, so that the component area is // completely covered with video; edges of the video that would go // beyond the boundaries of the component are cropped. import xm.components.FLVDisplay; myToobPlayer.display.resizeMode = FLVDisplay.rmFillOut;
bufferTime : Number
Specifies the number of seconds to buffer in memory before beginning to play a video. The default value is 5.
Example
myToobPlayer.display.bufferTime = 10;
time : Number
Sets or retrieves the current position of the playhead.
Example
// move the playhead to 00:30 myToobPlayer.display.time = 30;
duration : Number [read-only]
Indicates the duration of the video in seconds. The duration of the video is extracted from the video's metadata.
Example
myToobPlayer.display.addEventListener("meta", this);
myToobPlayer.autoPlay = true;
myToobPlayer.url = "video.flv";
function meta() {
if (myToobPlayer.display.duration == undefined) {
trace("video contains no metadata");
}
else {
trace("duration: "+myToobPlayer.display.duration);
}
}
preferredWidth : Number
Specifies the preferred width of the video, so that the video can be properly resized. The preferred width is extracted from the FLV's metadata.
Example
myToobPlayer.display.addEventListener("meta", this);
myToobPlayer.autoPlay = true;
myToobPlayer.url = "video.flv";
function meta() {
if (myToobPlayer.display.duration == undefined) {
trace("video contains no metadata");
}
else {
trace("width: "+myToobPlayer.display.preferredWidth);
trace("height: "+myToobPlayer.display.preferredHeight);
}
}
preferredHeight : Number
Specifies the preferred height of the video, so that the video can be properly resized. The preferred height is extracted from the FLV's metadata.
Example
myToobPlayer.display.addEventListener("meta", this);
myToobPlayer.autoPlay = true;
myToobPlayer.url = "video.flv";
function meta() {
if (myToobPlayer.display.duration == undefined) {
trace("video contains no metadata");
}
else {
trace("width: "+myToobPlayer.display.preferredWidth);
trace("height: "+myToobPlayer.display.preferredHeight);
}
}
opening : Boolean [read-only]
Indicates the interval between the opening (play method) and the start of the video.
started : Boolean [read-only]
Indicates whether or not the video has started.
playing : Boolean [read-only]
Indicates whether or not the video is playing.
preloading : Boolean [read-only]
Indicates whether or not the video is still downloading.
video : Object
Reference to the Video object (see Flash documentation) used by the component.
nc : NetConnection
Reference to the NetConnection object (see Flash documentation) used by the component.
ns : NetStream
Reference to the NetStream object (see Flash documentation) used by the component.
Properties inherited from the resizableClip class
width : Number
The width of the component, in pixels. (This value is always rounded.)
Example
// width of the video display area
trace("w: "+myToobPlayer.display.width);
height : Number
The height of the component, in pixels. (This value is always rounded.)
Example
// height of the video display area
trace("h: "+myToobPlayer.display.height);
minWidth : Number
The minimal width of the component, in pixels. By default, equals to 0.
minHeight : Number
The minimal height of the component, in pixels. By default, equals to 0.
maxWidth : Number
The maximal width of the component, in pixels. By default, equals to Infinity.
maxHeight : Number
The maximal height of the component, in pixels. By default, equals to Infinity.
Aligner : xm.corpus.aligner
Reference to the aligner object that manages the aligning within the component.
Events
resizeVideo
Broadcast when the video has been resized.
Example
myToobPlayer.display.addEventListener("resizeVideo", this);
myToobPlayer.display.resizeMode = rmCenter;
function resizeVideo() {
trace("w: "+myToobPlayer.display.video._width+" h: "+myToobPlayer.display.video._height);
}
start
Broadcast when the video has started playing.
complete
Broadcast when the video has finished playing.
Example
myToobPlayer.display.addEventListener("complete", this);
function complete() {
if (myToobPlayer.display.playing) {
// finished playing current video; play next video
myToobPlayer.url = nextClip;
}
}
progress
Indicates progress in number of downloaded bytes. bl and bt passed in the event object indicate the bytes downloaded (size of the downloaded portion of the video) and the bytes total (total size of the video), respectively.
Example
myToobPlayer.display.addEventListener("progress", this);
function progress(e:Object):Void {
trace("loaded: "+e.bl/e.bt*100);
}
loaded
Broadcast when the video has finished downloading.
Example
myToobPlayer.display.addEventListener("loaded", this);
function loaded(e:Object):Void {
trace("downloading complete");
}
change
Broadcast when the position of the playhead has changed.
Example
myToobPlayer.display.addEventListener("change", this);
function change():Void {
trace("time: "+myToobPlayer.display.time);
}
open
Broadcast upon the opening of the video (triggered by the play method); the video is about to play, but has not actually started playing yet.
Example
myToobPlayer.display.addEventListener("open", this);
function open():Void {
trace("Connecting...");
}
closed
Broadcast when the video has been closed. The stop method is typically used to stop and close the video.
seeking
Broadcast upon the repositioning of the playhead in the video (e.g. using the scrubber, or using the time property directly).
error
Broadcast every time a NetStream.Play.StreamNotFound error is posted for the NetStream object.
Example
myToobPlayer.display.addEventListener("error", this);
function error() {
trace("Cannot load the video.");
}
meta
Broadcast when the information embedded in the FLV file being played has become available. At this time the preferredWidth, preferredheight, and duration properties will be automatically populated from the metadata. meta object passed in the event object contains all available metadata.
Example
myToobPlayer.display.addEventListener("meta", this);
function meta(e:Object):Void {
var meta:Object = e.meta;
for (var propName:String in meta) {
trace(propName + " = " + meta[propName]);
}
}
volume
Broadcast when the volume has changed.
zoom
Broadcast when the magnification of the video (the zoom property) has changed.
playing
Broadcast when the video had started playing.
Example
myToobPlayer.display.addEventListener("playing", this);
function playing() {
trace("Video is playing.");
}
notPlaying
Broadcast when the video had stopped playing (video paused or stopped).
Example
myToobPlayer.display.addEventListener("notPlaying", this);
function notPlaying() {
trace("Video is paused/stopped.");
}
bufferEmpty
Broadcast when the buffer is empty, i.e. the video had been interrupted because of the slow download.
bufferFull
Broadcast when the buffer is full, i.e. the video can begin playing.
bufferFlush
Broadcast when the remaining buffer can be emptied, i.e. the download has completed.
acquiringYouTubeUrl
Broadcast by the ToobPlayer component, before attempting to resolve the YouTube ID specified by its url property.
Example
myToobPlayer.display.addEventListener("acquiringYouTubeUrl", this);
function acquiringYouTubeUrl() {
trace("Resolving YouTube video ID.");
}
acquiredYouTubeUrl
Broadcast by the ToobPlayer component, after the YouTube ID specified by its url property has been successfully resolved.
Example
myToobPlayer.display.addEventListener("acquiredYouTubeUrl", this);
function acquiredYouTubeUrl() {
trace("The direct link to the FLV is now ready.");
}
errorAcquiringYouTubeUrl
Broadcast by the ToobPlayer component, if the YouTube ID specified by its url property could not be resolved (either due to a connection problems or an invalid ID).
Example
myToobPlayer.display.addEventListener("errorAcquiringYouTubeUrl", this);
function acquiredYouTubeUrl() {
trace("The link to the FLV could not be resolved.");
}
Events inherited from the resizableClip class
resize
Broadcast when the component has been resized.
Example
myToobPlayer.display.addEventListener("resize", this);
myToobPlayer._x = 0;
myToobPlayer._y = 0;
myToobPlayer.setSize(Stage.width, Stage.height);
function resize() {
trace("display.w: "+myToobPlayer.display.width+" display.h: "+myToobPlayer.display.height);
}
Possible output:
display.w: 1280 display.h: 996
Class Summary
Methods
Methods inherited from the resizableClip class
- setSize(p_width:Number, p_height:Number) : Void
- addEventListener(p_eventName:String, p_handler) : Void
- addEventListenerL(p_eventName:String, p_obj:Object, p_handler) : Void
- removeEventListener(p_eventName:String, p_handler) : Void
- removeEventListenerL(p_eventName:String, p_obj:Object, p_handler) : Void
- removeAllEventListeners(p_eventName:String) : Void
- dispatchEvent(p_eventObj:Object) : Void
Properties
- url : String
- autoPlay : Boolean
- autoRepeat : Boolean
- volume : Number
- zoom : Number
- resizeMode : String
- bufferTime : Number
- time : Number
- duration : Number [read-only]
- preferredWidth : Number
- preferredHeight : Number
- opening : Boolean [read-only]
- started : Boolean [read-only]
- playing : Boolean [read-only]
- preloading : Boolean [read-only]
- video : Object
- nc : NetConnection
- ns : NetStream
Properties inherited from the resizableClip class
- width : Number
- height : Number
- minWidth : Number
- minHeight : Number
- maxWidth : Number
- maxHeight : Number
- Aligner : xm.corpus.aligner
Events
- resizeVideo
- start
- complete
- progress
- loaded
- change
- opening
- closed
- seeking
- error
- meta
- volume
- zoom
- playing
- notPlaying
- bufferEmpty
- bufferFull
- bufferFlush
- acquiringYouTubeUrl
- acquiredYouTubeUrl
- errorAcquiringYouTubeUrl
Events inherited from the resizableClip class
License and Links
The MIT License
Copyright (c) 2008 Elvis Mehmedović
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.