home *** CD-ROM | disk | FTP | other *** search
/ i·claim - visualizing argument / ICLAIM.ISO / mac / t_02.swf / scripts / __Packages / mx / controls / streamingmedia / MP3Player.as < prev    next >
Text File  |  2005-02-25  |  4KB  |  192 lines

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