home *** CD-ROM | disk | FTP | other *** search
/ i·claim - visualizing argument / ICLAIM.ISO / pc / t_06.swf / scripts / __Packages / mx / controls / streamingmedia / FLVPlayer.as < prev    next >
Encoding:
Text File  |  2005-02-28  |  5.0 KB  |  226 lines

  1. class mx.controls.streamingmedia.FLVPlayer extends mx.controls.streamingmedia.AbstractPlayer
  2. {
  3.    var _mediaUrl;
  4.    var _videoHolder;
  5.    var _video;
  6.    var _totalTime;
  7.    var _listeners;
  8.    var _isLoaded;
  9.    var _sound;
  10.    var _ns;
  11.    var _nc;
  12.    var _videoHeight;
  13.    var _videoWidth;
  14.    var _momentaryPlayId;
  15.    function FLVPlayer(aMediaUrl, aVideoHolder, aTotalTime)
  16.    {
  17.       super();
  18.       if(aMediaUrl == null || aVideoHolder == null || aTotalTime == null)
  19.       {
  20.       }
  21.       this._mediaUrl = aMediaUrl;
  22.       this._videoHolder = aVideoHolder;
  23.       this._video = this._videoHolder._video;
  24.       this._totalTime = aTotalTime;
  25.       this.init();
  26.    }
  27.    function init()
  28.    {
  29.       this._listeners = new Array();
  30.       this.setPlaying(false);
  31.       this._isLoaded = false;
  32.       this._sound = new Sound(this._videoHolder);
  33.       this.setVolume(mx.controls.streamingmedia.StreamingMediaConstants.DEFAULT_VOLUME);
  34.    }
  35.    function addListener(aListener)
  36.    {
  37.       this._listeners.push(aListener);
  38.    }
  39.    function removeAllListeners()
  40.    {
  41.       this._listeners.length = 0;
  42.    }
  43.    function broadcastEvent(status)
  44.    {
  45.       var _loc2_ = 0;
  46.       while(_loc2_ < this._listeners.length)
  47.       {
  48.          this._listeners[_loc2_].handlePlayer(this,status);
  49.          _loc2_ = _loc2_ + 1;
  50.       }
  51.    }
  52.    function bufferIsFull()
  53.    {
  54.       this.broadcastEvent("start");
  55.       if(!this.isPlaying())
  56.       {
  57.          this.pause();
  58.       }
  59.    }
  60.    function resizeVideo()
  61.    {
  62.       this.broadcastEvent("resizeVideo");
  63.       if(!this.isPlaying())
  64.       {
  65.          this.pause();
  66.       }
  67.    }
  68.    function toString()
  69.    {
  70.       return "FLVPlayer: Playing " + this.getMediaUrl();
  71.    }
  72.    function close()
  73.    {
  74.       this._ns.close();
  75.       this._nc.close();
  76.       this._video.clear();
  77.    }
  78.    function load()
  79.    {
  80.       this._nc = new NetConnection();
  81.       this._nc.connect(null);
  82.       this._ns = new mx.controls.streamingmedia.PlayerNetStream(this._nc,this);
  83.       this.assignBufferTime();
  84.       this._video.attachVideo(this._ns);
  85.       this._videoHeight = this._video.height;
  86.       this._videoWidth = this._video.width;
  87.       this._videoHolder.attachAudio(this._ns);
  88.       this._ns.play(this._mediaUrl);
  89.       this._isLoaded = true;
  90.       this._videoHolder._visible = false;
  91.       this.setPlaying(false);
  92.    }
  93.    function assignBufferTime()
  94.    {
  95.       var _loc2_ = this._totalTime / 4;
  96.       if(_loc2_ < 0.1)
  97.       {
  98.          _loc2_ = 0.1;
  99.       }
  100.       else if(_loc2_ > 5)
  101.       {
  102.          _loc2_ = 5;
  103.       }
  104.       this._ns.setBufferTime(_loc2_);
  105.    }
  106.    function play(startingPoint)
  107.    {
  108.       if(!this._isLoaded)
  109.       {
  110.          this.load();
  111.       }
  112.       if(startingPoint != null)
  113.       {
  114.          this._ns.seek(startingPoint);
  115.       }
  116.       this._ns.pause(false);
  117.       this.setPlaying(true);
  118.    }
  119.    function pause()
  120.    {
  121.       this._ns.pause(true);
  122.       this.setPlaying(false);
  123.    }
  124.    function stop()
  125.    {
  126.       this.pause();
  127.       this.setPlayheadTime(0);
  128.    }
  129.    function getPlayheadTime()
  130.    {
  131.       return this._ns.time;
  132.    }
  133.    function setPlayheadTime(position)
  134.    {
  135.       this._ns.seek(position);
  136.       if(!mx.controls.streamingmedia.StreamingMediaConstants.SCRUBBING)
  137.       {
  138.          if(!this.isPlaying())
  139.          {
  140.             this._ns.pause(false);
  141.             this._momentaryPlayId = setInterval(this,"doneUpdateFrame",50);
  142.          }
  143.       }
  144.    }
  145.    function doneUpdateFrame()
  146.    {
  147.       clearInterval(this._momentaryPlayId);
  148.       this._momentaryPlayId = null;
  149.       this._ns.pause(true);
  150.    }
  151.    function playStopped()
  152.    {
  153.       this.pause();
  154.       this.broadcastEvent("complete");
  155.    }
  156.    function getMediaUrl()
  157.    {
  158.       return this._mediaUrl;
  159.    }
  160.    function setMediaUrl(aUrl)
  161.    {
  162.       this._mediaUrl = aUrl;
  163.       this._isLoaded = false;
  164.       if(this.isPlaying())
  165.       {
  166.          this.play(0);
  167.       }
  168.       else
  169.       {
  170.          this.load();
  171.       }
  172.    }
  173.    function getVolume()
  174.    {
  175.       return this._sound.getVolume();
  176.    }
  177.    function setVolume(aVol)
  178.    {
  179.       this._sound.setVolume(aVol);
  180.    }
  181.    function getMediaBytesLoaded()
  182.    {
  183.       return this._ns.bytesLoaded;
  184.    }
  185.    function getMediaBytesTotal()
  186.    {
  187.       return this._ns.bytesTotal;
  188.    }
  189.    function getTotalTime()
  190.    {
  191.       return this._totalTime;
  192.    }
  193.    function setTotalTime(aTime)
  194.    {
  195.       this._totalTime = aTime;
  196.       this.assignBufferTime();
  197.    }
  198.    function mediaLoaded()
  199.    {
  200.    }
  201.    function logError(error)
  202.    {
  203.    }
  204.    function isSizeSet()
  205.    {
  206.       if(this._video.width > 0 && this._video.height > 0)
  207.       {
  208.          return true;
  209.       }
  210.       return false;
  211.    }
  212.    function isSizeChange()
  213.    {
  214.       if(this._video.width != this._videoWidth || this._video.height != this._videoHeight)
  215.       {
  216.          this._videoWidth = this._video.width;
  217.          this._videoHeight = this._video.height;
  218.          return true;
  219.       }
  220.       return false;
  221.    }
  222.    function setSeeking(isSeeking)
  223.    {
  224.    }
  225. }
  226.