home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / sky-chopper.swf / scripts / __Packages / mx / controls / streamingmedia / MP3Player.as < prev    next >
Encoding:
Text File  |  2005-09-29  |  4.5 KB  |  193 lines

  1. class mx.controls.streamingmedia.MP3Player extends mx.controls.streamingmedia.AbstractPlayer implements mx.controls.streamingmedia.IPlayer
  2. {
  3.    var _mediaUrl;
  4.    var _soundHolder;
  5.    var _positionOnLoad;
  6.    var _volume;
  7.    var _listeners;
  8.    var _sound;
  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.          throw new Error("A media url and a sound holder clip must be passed to MP3Player\'s constructor");
  18.       }
  19.       this._mediaUrl = aMediaUrl;
  20.       this._soundHolder = aSoundHolder;
  21.       this.init();
  22.    }
  23.    function willStop()
  24.    {
  25.       return this._positionOnLoad == mx.controls.streamingmedia.MP3Player.STOP;
  26.    }
  27.    function init()
  28.    {
  29.       this._volume = mx.controls.streamingmedia.StreamingMediaConstants.DEFAULT_VOLUME;
  30.       this._listeners = new Array();
  31.       this._sound = new Sound();
  32.       var _loc3_ = Object(this._sound);
  33.       _loc3_.player = this;
  34.       this._sound.onSoundComplete = function()
  35.       {
  36.          var _loc3_ = Object(this);
  37.          var _loc2_ = _loc3_.player;
  38.          _loc2_.setPlaying(false);
  39.          _loc2_.broadcastEvent("complete");
  40.       };
  41.       this._recentPosition = 0;
  42.       this._loaded = false;
  43.       this._positionOnLoad = mx.controls.streamingmedia.MP3Player.STOP;
  44.       this.setPlaying(false);
  45.    }
  46.    function playStarted()
  47.    {
  48.       this._loaded = true;
  49.       this.initializeVolume();
  50.       if(this._positionOnLoad == mx.controls.streamingmedia.MP3Player.STOP)
  51.       {
  52.          this.stop();
  53.       }
  54.       else
  55.       {
  56.          this.play(this._positionOnLoad);
  57.       }
  58.    }
  59.    function addListener(aListener)
  60.    {
  61.       this._listeners.push(aListener);
  62.    }
  63.    function removeAllListeners()
  64.    {
  65.       this._listeners.length = 0;
  66.    }
  67.    function broadcastEvent(status)
  68.    {
  69.       var _loc2_ = 0;
  70.       while(_loc2_ < this._listeners.length)
  71.       {
  72.          this._listeners[_loc2_].handlePlayer(this,status);
  73.          _loc2_ = _loc2_ + 1;
  74.       }
  75.    }
  76.    function load()
  77.    {
  78.       this.setPlaying(true);
  79.       this._positionOnLoad = mx.controls.streamingmedia.MP3Player.STOP;
  80.       this._sound.loadSound(this._mediaUrl,true);
  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.       }
  97.       this.setPlaying(true);
  98.    }
  99.    function pause()
  100.    {
  101.       this._recentPosition = this._sound.position / 1000;
  102.       this._sound.stop();
  103.       this.setPlaying(false);
  104.    }
  105.    function stop()
  106.    {
  107.       this._recentPosition = 0;
  108.       this._sound.stop();
  109.       this.setPlaying(false);
  110.    }
  111.    function getPlayheadTime()
  112.    {
  113.       var _loc2_ = !this.isPlaying() ? this._recentPosition : this._sound.position / 1000;
  114.       return _loc2_;
  115.    }
  116.    function setPlayheadTime(aPosition)
  117.    {
  118.       this._recentPosition = aPosition;
  119.       if(this.isPlaying())
  120.       {
  121.          this.play(aPosition);
  122.       }
  123.    }
  124.    function getMediaUrl()
  125.    {
  126.       return this._mediaUrl;
  127.    }
  128.    function setMediaUrl(aUrl)
  129.    {
  130.       this._loaded = false;
  131.       this._mediaUrl = aUrl;
  132.       if(this.isPlaying())
  133.       {
  134.          this.play(0);
  135.       }
  136.       else
  137.       {
  138.          this._recentPosition = 0;
  139.          this.load();
  140.       }
  141.    }
  142.    function getVolume()
  143.    {
  144.       return this._sound.getVolume();
  145.    }
  146.    function setVolume(aVol)
  147.    {
  148.       this._sound.setVolume(aVol);
  149.       this._volume = aVol;
  150.    }
  151.    function getAssignedVolume()
  152.    {
  153.       return this._volume;
  154.    }
  155.    function initializeVolume()
  156.    {
  157.       this.setVolume(this._volume);
  158.    }
  159.    function getMediaBytesLoaded()
  160.    {
  161.       return this._sound.getBytesLoaded();
  162.    }
  163.    function getMediaBytesTotal()
  164.    {
  165.       return this._sound.getBytesTotal();
  166.    }
  167.    function getTotalTime()
  168.    {
  169.       var _loc2_ = this._sound.duration * this._sound.getBytesTotal() / this._sound.getBytesLoaded();
  170.       return _loc2_ / 1000;
  171.    }
  172.    function bufferIsFull()
  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. }
  193.