dojox/av/FLVideo.js

  • Provides:

    • dojox.av.FLVideo
  • Requires:

    • dijit._Widget in common in project dijit
    • dojox.embed.Flash in common
    • dojox.av._Media in common
  • dojox.av.FLVideo

    • type
      Function
    • chains:
      • dijit._Widget: (prototype)
      • dijit._Widget: (call)
      • dojox.av._Media: (call)
    • mixins:
      • dojox.av._Media.prototype: (prototype)
    • summary
      Inserts a Flash FLV video into the HTML page and provides methods
      and events for controlling the video. Also plays the H264/M4V codec
      with a little trickery: change the '.M4V' extension to '.flv'.
    • example
      markup:
      
      	<div id="vid" initialVolume=".7",
      		mediaUrl="../resources/Grog.flv"
      		dojoType="dojox.av.FLVideo"></div>
      programmatic:
      
      	new dojox.av.FLVideo({
      		initialVolume:.7,
      		mediaUrl:"../resources/Grog.flv"
      	}, "vid");
      
      
      mediaUrl: String
      REQUIRED: The Url of the video file that will be played.
      NOTE: Must be either an absolute URL or relative to the HTML file.
      Relative paths will be converted to abslute paths
    • parameters:
      • options: (typeof Object)
    • source: [view]
      dojo.provide("dojox.av.FLVideo");
      dojo.experimental("dojox.av.FLVideo");
      dojo.require("dijit._Widget");
      dojo.require("dojox.embed.Flash");
      dojo.require("dojox.av._Media");


      dojo.declare("dojox.av.FLVideo", [dijit._Widget, dojox.av._Media], {


       // summary:
       //  Inserts a Flash FLV video into the HTML page and provides methods
       //  and events for controlling the video. Also plays the H264/M4V codec
       //  with a little trickery: change the '.M4V' extension to '.flv'.
       //
       // example:
       //
       //  markup:
       //  | 
       //  |  mediaUrl="../resources/Grog.flv"
       //  |  dojoType="dojox.av.FLVideo">

       //  programmatic:
       //  | new dojox.av.FLVideo({
       //  |  initialVolume:.7,
       //  |  mediaUrl:"../resources/Grog.flv"
       //  | }, "vid");
       //
       // mediaUrl: String
       //   REQUIRED: The Url of the video file that will be played.
       //  NOTE: Must be either an absolute URL or relative to the HTML file.
       //  Relative paths will be converted to abslute paths
       //
       // _swfPath: Uri
       //  The path to the video player SWF resource
       _swfPath: dojo.moduleUrl("dojox.av", "resources/video.swf"),
       //
       //
       constructor: function(/*Object*/options){
        // Provide this function for the SWF to ensure that the it is playing
        // in HTML.
        dojo.global.swfIsInHTML = function(){ return true; }
  • dojox.av.FLVideo._swfPath

    • type
      Uri
    • summary
      The path to the video player SWF resource
  • dojox.av.FLVideo.postCreate

    • type
      Function
    • source: [view]
        this._subs = [];
        this._cons = [];
        this.mediaUrl = this._normalizeUrl(this.mediaUrl);
        this.initialVolume = this._normalizeVolume(this.initialVolume);


        var args = {
         path:this._swfPath.uri,
         width:"100%",
         height:"100%",
         minimumVersion:9,
         expressInstall:true,
         params:{
          allowFullScreen: this.allowFullScreen,
          wmode:this.wmode,
          allowScriptAccess:this.allowScriptAccess,
          allowNetworking:this.allowNetworking
         },
         // only pass in simple variables - no deep objects
         vars:{
          videoUrl:this.mediaUrl,
          id:this.id,
          autoPlay:this.autoPlay,
          volume:this.initialVolume,
          isDebug:this.isDebug
         }
        };


        // Setting up dojo.subscribes that listens to events
        // from the player
        this._sub("stageClick", "onClick");
        this._sub("stageSized", "onSwfSized");
        this._sub("mediaStatus", "onPlayerStatus");
        this._sub("mediaMeta", "onMetaData");
        this._sub("mediaError", "onError");
        this._sub("mediaStart", "onStart");
        this._sub("mediaEnd", "onEnd");


        this._flashObject = new dojox.embed.Flash(args, this.domNode);
        this._flashObject.onError = function(err){
         console.error("Flash Error:", err);
        };
        this._flashObject.onLoad = dojo.hitch(this, function(mov){
         this.flashMedia = mov;
         this.isPlaying = this.autoPlay;
         this.isStopped = !this.autoPlay;
         this.onLoad(this.flashMedia);
         this._initStatus();
         this._update();
        });
        this.inherited(arguments);
    • summary
      Initialize the media.
  • dojox.av.FLVideo.play

    • type
      Function
    • parameters:
      • newUrl: (typeof String)
    • source: [view]
        this.isPlaying = true;
        this.isStopped = false;
        this.flashMedia.doPlay(this._normalizeUrl(newUrl));
    • summary
      Plays the video. If an url is passed in, plays the new link.
  • dojox.av.FLVideo.pause

    • type
      Function
    • source: [view]
        this.isPlaying = false;
        this.isStopped = false;
        if(this.onPaused){
         this.onPaused();
        }
        this.flashMedia.pause();
    • summary
      Pauses the video
  • dojox.av.FLVideo.seek

    • type
      Function
    • parameters:
      • time: (typeof Float)
    • source: [view]
        this.flashMedia.seek(time);
    • summary
      Goes to the time passed in the argument
  • dojox.av.FLVideo.volume

    • type
      Function
    • parameters:
      • vol: (typeof Float)
    • source: [view]
        if(vol){
         if(!this.flashMedia) {
          this.initialVolume = vol;
         }
         this.flashMedia.setVolume(this._normalizeVolume(vol));
        }
        if(!this.flashMedia || !this.flashMedia.doGetVolume) {
         return this.initialVolume;
        }
        return this.flashMedia.getVolume(); // Float
    • summary
      Sets the volume of the video to the time in the
      argument - between 0 - 1.
    • returns
      Float
  • dojox.av.FLVideo.onLoad

    • type
      Function
    • parameters:
      • mov: (typeof )
    • source: [view]
        // summary:
        //   Fired when the SWF player has loaded
        //   NOT when the video has loaded
    • summary
      Fired when the SWF player has loaded
      NOT when the video has loaded
  • dojox.av.FLVideo.onDownloaded

    • type
      Function
    • parameters:
      • percent: (typeof )
    • source: [view]
        // summary:
        //  Fires the amount of that the media has been
        //  downloaded. Number, 0-100
    • summary
      Fires the amount of that the media has been
      downloaded. Number, 0-100
  • dojox.av.FLVideo.onClick

    • type
      Function
    • parameters:
      • evt: (typeof )
    • source: [view]
        // summary:
        //   Fires when the player is clicked
        //   Could be used to toggle play/pause, or
        //   do an external activity, like opening a new
        //  window.
    • summary
      Fires when the player is clicked
      Could be used to toggle play/pause, or
      do an external activity, like opening a new
      window.
  • dojox.av.FLVideo.onSwfSized

    • type
      Function
    • parameters:
      • data: (typeof )
    • source: [view]
        // summary:
        //   Fired on SWF resize, or when its
        //   toggled between fullscreen.
    • summary
      Fired on SWF resize, or when its
      toggled between fullscreen.
  • dojox.av.FLVideo.onMetaData

    • type
      Function
    • parameters:
      • data: (typeof )
      • evt: (typeof )
    • source: [view]
        // summary:
        //   The video properties. Width, height, duration, etc.
        //   NOTE:  if data is empty, this is an older FLV with no meta data.
        //     Duration cannot be determined. In original FLVs, duration
        //    could only be obtained with Flash Media Server.
        //   NOTE:  Older FLVs can still return width and height
        //    and will do so on a second event call
    • summary
      The video properties. Width, height, duration, etc.
      NOTE: 	if data is empty, this is an older FLV with no meta data.
      Duration cannot be determined. In original FLVs, duration
      could only be obtained with Flash Media Server.
      NOTE: 	Older FLVs can still return width and height
      and will do so on a second event call
  • dojox.av.FLVideo.onPosition

    • type
      Function
    • parameters:
      • time: (typeof )
    • source: [view]
        // summary:
        //  The position of the playhead in seconds
    • summary
      The position of the playhead in seconds
  • dojox.av.FLVideo.onStart

    • type
      Function
    • parameters:
      • data: (typeof )
    • source: [view]
        // summary:
        //   Fires when video starts
        //   Good for setting the play button to pause
        //   during an autoPlay for example
    • summary
      Fires when video starts
      Good for setting the play button to pause
      during an autoPlay for example
  • dojox.av.FLVideo.onPlay

    • type
      Function
    • parameters:
      • data: (typeof )
    • source: [view]
        // summary:
        //   Fires when video starts and resumes
    • summary
      Fires when video starts and resumes
  • dojox.av.FLVideo.onPause

    • type
      Function
    • parameters:
      • data: (typeof )
    • source: [view]
        // summary:
        //   Fires when the pause button is clicked
    • summary
      Fires when the pause button is clicked
  • dojox.av.FLVideo.onEnd

    • type
      Function
    • parameters:
      • data: (typeof )
    • source: [view]
        // summary:
        //   Fires when video ends
        //   Could be used to change pause button to play
        //   or show a post video graphic, like YouTube
    • summary
      Fires when video ends
      Could be used to change pause button to play
      or show a post video graphic, like YouTube
  • dojox.av.FLVideo.onStop

    • type
      Function
    • source: [view]
        // summary:
        // Fire when the Stop button is clicked
        // TODO:  This is not hooked up yet and shouldn't
        //   fire.
    • summary
      Fire when the Stop button is clicked
      TODO: 	This is not hooked up yet and shouldn't
      fire.
  • dojox.av.FLVideo.onBuffer

    • type
      Function
    • parameters:
      • isBuffering: (typeof )
    • source: [view]
        this.isBuffering = isBuffering;
    • summary
      Fires a boolean to tell if media
      is paused for buffering or if buffering
      has finished
  • dojox.av.FLVideo.onError

    • type
      Function
    • parameters:
      • data: (typeof )
      • url: (typeof )
    • source: [view]
        // summary:
        //   Fired when the player encounters an error
        // example:
        //  | console.warn("ERROR-"+data.type.toUpperCase()+":",
        //  |  data.info.code, " - URL:", url);
    • summary
      Fired when the player encounters an error
    • example
      
       console.warn("ERROR-"+data.type.toUpperCase()+":",
      		data.info.code, " - URL:", url);
  • dojox.av.FLVideo.onStatus

    • type
      Function
    • parameters:
      • data: (typeof )
    • source: [view]
        // summary:
        //   Simple status
    • summary
      Simple status
  • dojox.av.FLVideo.onPlayerStatus

    • type
      Function
    • parameters:
      • data: (typeof )
    • source: [view]
        // summary:
        //   The status of the video from the SWF
        //   playing, stopped, bufering, etc.
    • summary
      The status of the video from the SWF
      playing, stopped, bufering, etc.
  • dojox.av.FLVideo.onResize

    • type
      Function
    • source: [view]
        // summary:
        //  Fired on page resize
    • summary
      Fired on page resize
  • dojox.av.FLVideo._checkBuffer

    • type
      Function
    • parameters:
      • time: (typeof Float)
      • bufferLength: (typeof Float)
    • source: [view]
        if(this.percentDownloaded == 100){
         if(this.isBuffering){
          this.onBuffer(false);
          this.flashMedia.doPlay();
         }
         return;
        }


        if(!this.isBuffering && bufferLength<.1){
         this.onBuffer(true);
         this.flashMedia.pause();
         return;
        }


        var timePercentLoad = this.percentDownloaded*.01*this.duration;


        // check if start buffer needed
        if(!this.isBuffering && time+this.minBufferTime*.001>timePercentLoad){
         this.onBuffer(true);
         this.flashMedia.pause();


        // check if end buffer needed
        }else if(this.isBuffering && time+this.bufferTime*.001<=timePercentLoad){
         this.onBuffer(false);
         this.flashMedia.doPlay();
        }
    • summary
      Checks that there is a proper buffer time between
      current playhead time and the amount of data loaded.
      Works only on FLVs with a duration (not older). Pauses
      the video while continuing download.
  • dojox.av.FLVideo._update

    • type
      Function
    • source: [view]
        var time = Math.min(this.getTime() || 0, this.duration);
        var dObj = this.flashMedia.getLoaded();
        this.percentDownloaded = Math.ceil(dObj.bytesLoaded/dObj.bytesTotal*100);
        this.onDownloaded(this.percentDownloaded);
        this.onPosition(time);
        if(this.duration){
         this._checkBuffer(time, dObj.buffer);
        }
        // FIXME: need to remove this on destroy
        this._updateHandle = setTimeout(dojo.hitch(this, "_update"), this.updateTime);
    • summary
      Helper function to fire onPosition, check download progress,
      and check buffer.
  • dojox.av.FLVideo.destroy

    • type
      Function
    • source: [view]
        clearTimeout(this._updateHandle);
        dojo.disconnect(this._positionHandle);
        this.inherited(arguments);
    • summary
  • dojox.av.FLVideo._subs

    • summary
  • dojox.av.FLVideo._cons

    • summary
  • dojox.av.FLVideo.mediaUrl

    • summary
  • dojox.av.FLVideo.initialVolume

    • summary
  • dojox.av.FLVideo._flashObject

    • summary
  • dojox.av.FLVideo._flashObject.onError

    • summary
  • dojox.av.FLVideo._flashObject.onLoad

    • summary
  • dojox.av.FLVideo.flashMedia

    • summary
  • dojox.av.FLVideo.isPlaying

    • summary
  • dojox.av.FLVideo.isStopped

    • summary
  • dojox.av.FLVideo.postCreate._flashObject.onError

    • type
      Function
    • parameters:
      • err: (typeof )
    • source: [view]
         console.error("Flash Error:", err);
    • summary
  • dojox.av.FLVideo.isBuffering

    • summary
  • dojox.av.FLVideo.percentDownloaded

    • summary
  • dojox.av.FLVideo._updateHandle

    • summary
  • dojox.av

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary