/************************************************************************************************** BSD License The BSD License (http://www.opensource.org/licenses/bsd-license.php) specifies the terms and conditions of use for FAVideo: Copyright (c) 2007. Adobe Systems Incorporated. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ¥ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. ¥ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. ¥ Neither the name of Adobe Systems Incorporated nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIESOF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. For more information and updates for FAVideo, please visit: http://www.adobe.com/go/favideo/ **************************************************************************************************/ /* ---------------------------------------------------- * FAVideo system * * This system provide a simple method for embedding and controlling Flash video through Javascript. * * Dependencies: * - Requires AC_RunActiveContent.js *----------------------------------------------------- */ /* ---------------------------------------------------- * FAVideo * * FAVideo represents a video player instance on the page. It allows you to instantiate, control, * and listen to events from a Flash video player through Javascript. *----------------------------------------------------- */ FAVideo = function(divName, videoPath, width, height, options) { this.DEFAULT_SWF_PATH = "FAVideo"; // dot swf is added by AC_RunActiveContent this.DEFAULT_SKIN_PATH = "skins/ClearOverAll.swf"; this.DEFAULT_WIDTH = 320; this.DEFAULT_HEIGHT = 240; this.ERROR_DIV_NOT_FOUND = "The specified DIV element was not found."; //this.DEFAULT_SKIN_PATH = "skins/ClearExternalAll.swf"; this.id = FAVideoManagerInstance.addPlayer(this); // Manager manages multiple players this.rendered = false; this.inited = false; // Div name, flash name, and container name this.divName = divName; this.name = "FAVideo_" + divName; // Video props this.videoPath = videoPath; this.width = (width > 0) ? width : this.DEFAULT_WIDTH; this.height = (height > 0) ? height : this.DEFAULT_HEIGHT; // Initialize player this.player = null; this.initProperties(); this.setOptions(options); this.createPlayer(); this.render(); } /* ---------------------------------------------------- * Public API methods *----------------------------------------------------- */ /** * Play an FLV. Sets autoPlay to true. * * @param videoPath Path to the FLV. If the videoPath is null, and the FLV is playing, it will act as a play/pause toggle. * @param totalTime Optional totalTime to override the FLV's built in totalTime */ FAVideo.prototype.play = function(videoPath, totalTime) { this.autoPlay = true; if (totalTime != null) { this.setTotalTime(totalTime); } if (videoPath != null) { this.videoPath = videoPath; } if (this.videoPath == null && !this.firstLoad) { this.dispatchEvent({type:"error", error:"FAVideo::play - No videoPath has been set."}); return; } if (videoPath == null && this.firstLoad && !this.autoLoad) { // Allow play(null) to toggle playback videoPath = this.videoPath; } this.firstLoad = false; this.callMethod("playVideo", videoPath, totalTime); } /** * Load a video. Sets autoPlay to false. * * @param videoPath Path the the FLV. */ FAVideo.prototype.load = function(videoPath) { if (videoPath != null) { this.videoPath = videoPath; } if (this.videoPath == null) { this.dispatchEvent({type:"error", error:"FAVideo::loadVideo - No videoPath has been set."}); return; } this.firstLoad = false; this.autoPlay = false; this.callMethod("loadVideo", this.videoPath); } /** * Toggle the pause state of the video. * * @param pauseState The pause state. Setting pause state to true will pause the video. */ FAVideo.prototype.pause = function(pauseState) { this.callMethod("pause", pauseState); } /** * Stop playback of the video. */ FAVideo.prototype.stop = function() { this.callMethod("stop"); } /** * Seek the video to a specific position. * * @param seconds The number of seconds to seek the playhead to. */ FAVideo.prototype.seek = function(seconds) { this.callMethod("seek", seconds); } /** * Set the size of the video. * * @param width The width of the video. * @param height The height of the video. */ FAVideo.prototype.setSize = function(width, height) { this.width = width; this.height = height; // Change the DOM. Do not rerender. this.container.style.width = this.width + "px"; this.container.style.height = this.height + "px"; this.callMethod("setSize", this.width, this.height); } /** * Add an event listener to the video. * * @param eventType A string representing the type of event. e.g. "init" * @param object The scope of the listener function (usually "this"). * @param function The function to be called when the event is dispatched. */ FAVideo.prototype.addEventListener = function(eventType, object, functionRef) { if (this.listeners == null) { this.listeners = {}; } if (this.listeners[eventType] == null) { this.listeners[eventType] = []; } else { this.removeEventListener(eventType, object, functionRef); } this.listeners[eventType].push({target:object, func:functionRef}); } /** * Remove an event listener from the video. * * @param eventType A string representing the type of event. e.g. "init" * @param object The scope of the listener function (usually "this"). * @param functionRef The function to be called when the event is dispatched. */ FAVideo.prototype.removeEventListener = function(eventType, object, functionRef) { for (var i=0; i init: The player is initialized * > ready: The video is ready * > progress: The video is downloading. Properties: bytesLoaded, bytesTotal * > playHeadUpdate: The video playhead has moved. Properties: playheadTime, totalTime * > stateChange: The state of the video has changed. Properties: state * > change: The player has changed. * > complete: Playback is complete. * > metaData: The video has returned meta-data. Properties: infoObject * > cuePoint: The video has passed a cuePoint. Properties: infoObject * > error: An error has occurred. Properties: error */ /* ---------------------------------------------------- * Callbacks from flash *----------------------------------------------------- */ FAVideo.prototype.update = function(props) { for (var n in props) { this[n] = props[n]; // Set the internal property } props.type = "change"; this.dispatchEvent(props); // This needs to have an array of changed props. } FAVideo.prototype.event = function(eventName, evtObj) { switch (eventName) { case "progress": this.bytesLoaded = evtObj.bytesLoaded; this.bytesTotal = evtObj.bytesTotal; this.dispatchEvent({type:"progress", bytesLoaded:this.bytesLoaded, bytesTotal:this.bytesTotal}); break; case "playheadUpdate": this.playheadTime = evtObj.playheadTime; this.totalTime = evtObj.totalTime; this.dispatchEvent({type:"playheadUpdate", playheadTime:this.playheadTime, totalTime:this.totalTime}); break; case "stateChange": this.state = evtObj.state; this.dispatchEvent({type:"stateChange", state:this.state}); break; case "change": this.dispatchEvent({type:"change"}); break; case "complete": this.dispatchEvent({type:"complete"}); break; case "ready": this.dispatchEvent({type:"ready"}); break; case "metaData": this.dispatchEvent({type:"metaData", infoObject:evtObj}); break; case "cuePoint": this.dispatchEvent({type:"cuePoint", infoObject:evtObj}); break; case "init": this.inited = true; this.callMethod("setSize", this.width, this.height); // There is a bug in IE innerHTML. Tell flash what size it is. This will probably not work with liquid layouts in IE. this.invalidateProperty("clickToTogglePlay", "skinVisible", "skinAutoHide", "autoPlay", "autoLoad", "volume", "bufferTime", "videoScaleMode", "videoAlign", "playheadUpdateInterval", "skinPath", "previewImagePath"); this.validateNow(); this.makeDelayCalls(); if (this.autoPlay) { this.play(this.videoPath); } else if (this.autoLoad) { this.load(this.videoPath); } this.dispatchEvent({type:"init"}); break; } } /* ---------------------------------------------------- * Initialization methods *----------------------------------------------------- */ FAVideo.prototype.render = function() { var div = this.getElement(this.divName); if (div == null) { return; } this.pluginError = false; div.innerHTML = this.content; this.player = this.getElement(this.name); this.container = this.getElement(this.name + "_Container"); this.rendered = true; } FAVideo.prototype.setOptions = function(options) { if (options == null) { return; } // Create a hash of acceptable properties var hash = ["volume", "skinAutoHide", "skinVisible", "autoPlay","clickToTogglePlay","autoLoad","playHeadTime","totalTime","bufferTime","videoScaleMode","videoAlign","playheadUpdateInterval","skinPath","previewImagePath"]; for (var i=0;i" + flash + ""; return this.content; } /* ---------------------------------------------------- * Utility methods *----------------------------------------------------- */ FAVideo.prototype.getElement = function(id) { var elem; if (navigator.appName.indexOf("Microsoft") != -1) { return window[id] } else { if (document[id]) { elem = document[id]; } else { elem = document.getElementById(id); } return elem; } } // Mark a property as invalid, and create a timeout for redraw FAVideo.prototype.invalidateProperty = function() { if (this.invalidProperties == null) { this.invalidProperties = {}; } for (var i=0; i '; } str += ''; } else { str += '