home *** CD-ROM | disk | FTP | other *** search
/ i·claim - visualizing argument / ICLAIM.ISO / pc / gloss.swf / scripts / __Packages / mx / controls / streamingmedia / MP3Player.as < prev    next >
Encoding:
Text File  |  2005-02-26  |  4.5 KB  |  200 lines

  1. class mx.controls.streamingmedia.MP3Player extends mx.controls.streamingmedia.AbstractPlayer
  2. {
  3.    var _mediaUrl;
  4.    var _soundHolder;
  5.    var _positionOnLoad;
  6.    var _listeners;
  7.    var _sound;
  8.    var _volume;
  9.    var _recentPosition;
  10.    var _loaded;
  11.    static var STOP = -1;
  12.    function MP3Player(aMediaUrl, aSoundHolder)
  13.    {
  14.       super();
  15.       if(aMediaUrl == null || aSoundHolder == null)
  16.       {
  17.       }
  18.       this._mediaUrl = aMediaUrl;
  19.       this._soundHolder = aSoundHolder;
  20.       this.init();
  21.    }
  22.    function willStop()
  23.    {
  24.       return this._positionOnLoad == mx.controls.streamingmedia.MP3Player.STOP;
  25.    }
  26.    function init()
  27.    {
  28.       this._listeners = new Array();
  29.       this._sound = new Sound(this._soundHolder);
  30.       this._volume = mx.controls.streamingmedia.StreamingMediaConstants.DEFAULT_VOLUME;
  31.       var _loc4_ = Object(this._sound);
  32.       _loc4_.player = this;
  33.       this._sound.onSoundComplete = function()
  34.       {
  35.          var _loc3_ = Object(this);
  36.          var _loc2_ = _loc3_.player;
  37.          _loc2_.setPlaying(false);
  38.          _loc2_.broadcastEvent("complete");
  39.       };
  40.       this._recentPosition = 0;
  41.       this._loaded = false;
  42.       this._positionOnLoad = mx.controls.streamingmedia.MP3Player.STOP;
  43.       this.setPlaying(false);
  44.    }
  45.    function playStarted()
  46.    {
  47.       this._loaded = true;
  48.       this.initializeVolume();
  49.       if(this._positionOnLoad == mx.controls.streamingmedia.MP3Player.STOP)
  50.       {
  51.          this.stop();
  52.       }
  53.       else
  54.       {
  55.          this.play(this._positionOnLoad);
  56.       }
  57.    }
  58.    function addListener(aListener)
  59.    {
  60.       this._listeners.push(aListener);
  61.    }
  62.    function removeAllListeners()
  63.    {
  64.       this._listeners.length = 0;
  65.    }
  66.    function broadcastEvent(status)
  67.    {
  68.       var _loc2_ = 0;
  69.       while(_loc2_ < this._listeners.length)
  70.       {
  71.          this._listeners[_loc2_].handlePlayer(this,status);
  72.          _loc2_ = _loc2_ + 1;
  73.       }
  74.    }
  75.    function load()
  76.    {
  77.       this.setPlaying(true);
  78.       this._positionOnLoad = mx.controls.streamingmedia.MP3Player.STOP;
  79.       this._sound.loadSound(this._mediaUrl,true);
  80.       this._sound.setVolume(0);
  81.    }
  82.    function play(startingPoint)
  83.    {
  84.       if(startingPoint == null)
  85.       {
  86.          startingPoint = this._recentPosition;
  87.       }
  88.       if(this._loaded)
  89.       {
  90.          this._sound.start(startingPoint);
  91.       }
  92.       else
  93.       {
  94.          this._positionOnLoad = startingPoint;
  95.          this._sound.loadSound(this._mediaUrl,true);
  96.          this._sound.setVolume(0);
  97.       }
  98.       this.setPlaying(true);
  99.    }
  100.    function pause()
  101.    {
  102.       this._recentPosition = this._sound.position / 1000;
  103.       this._sound.stop();
  104.       this.setPlaying(false);
  105.    }
  106.    function stop()
  107.    {
  108.       this._recentPosition = 0;
  109.       this._sound.stop();
  110.       this.setPlaying(false);
  111.    }
  112.    function getPlayheadTime()
  113.    {
  114.       var _loc2_ = !this.isPlaying() ? this._recentPosition : this._sound.position / 1000;
  115.       return _loc2_;
  116.    }
  117.    function setPlayheadTime(aPosition)
  118.    {
  119.       this._recentPosition = aPosition;
  120.       if(this.isPlaying())
  121.       {
  122.          this.play(aPosition);
  123.       }
  124.    }
  125.    function getMediaUrl()
  126.    {
  127.       return this._mediaUrl;
  128.    }
  129.    function setMediaUrl(aUrl)
  130.    {
  131.       this._loaded = false;
  132.       this._mediaUrl = aUrl;
  133.       if(this.isPlaying())
  134.       {
  135.          this.play(0);
  136.       }
  137.       else
  138.       {
  139.          this._recentPosition = 0;
  140.          this.load();
  141.       }
  142.    }
  143.    function getVolume()
  144.    {
  145.       return this._volume;
  146.    }
  147.    function setVolume(aVol)
  148.    {
  149.       this._sound.setVolume(aVol);
  150.       this._volume = aVol;
  151.    }
  152.    function initializeVolume()
  153.    {
  154.       this.setVolume(this._volume);
  155.    }
  156.    function getMediaBytesLoaded()
  157.    {
  158.       return this._sound.getBytesLoaded();
  159.    }
  160.    function getMediaBytesTotal()
  161.    {
  162.       return this._sound.getBytesTotal();
  163.    }
  164.    function getTotalTime()
  165.    {
  166.       var _loc2_ = this._sound.duration * this._sound.getBytesTotal() / this._sound.getBytesLoaded();
  167.       return _loc2_ / 1000;
  168.    }
  169.    function bufferIsFull()
  170.    {
  171.    }
  172.    function resizeVideo()
  173.    {
  174.    }
  175.    function playStopped()
  176.    {
  177.    }
  178.    function mediaLoaded()
  179.    {
  180.    }
  181.    function close()
  182.    {
  183.       this._sound.stop();
  184.    }
  185.    function logError(error)
  186.    {
  187.    }
  188.    function isSizeSet()
  189.    {
  190.       return false;
  191.    }
  192.    function isSizeChange()
  193.    {
  194.       return false;
  195.    }
  196.    function setSeeking(isSeeking)
  197.    {
  198.    }
  199. }
  200.