Posted By

chrisaiv on 06/13/07


Tagged

streaming mp3 as2


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

arala22
mattlohmann


AS2: Dynamically Load an MP3


 / Published in: ActionScript
 

I needed a way to dynamically stream mp3s. I coupled this with an XML File that had all the mp3's listed.

  1. /*************************
  2. Initialize Variables
  3. *************************/
  4. var pos:Number;
  5. var s:Sound = new Sound();
  6. s.onSoundComplete = playSong;
  7. s.setVolume(75);
  8.  
  9. /*************************
  10. Play Song
  11. *************************/
  12. function playSong(song:String){
  13. s = new Sound();
  14. s.onSoundComplete = playSong;
  15. s.setVolume(75);
  16. this.onEnterFrame = checkSound;
  17. s.loadSound(song, true);
  18. }
  19. function checkSound(){
  20. var percent:Number = Math.round((s.position / s.duration) * 100);
  21. if(percent != NaN){
  22. trace(percent);
  23. }
  24. }
  25. /*************************
  26. Pause Song (Create a Button that says play_btn.onRelease = pauseSong;)
  27. *************************/
  28. function pauseSong():Void{
  29. pos = s.position;
  30. s.stop();
  31. }
  32. function unpauseSong():Void{
  33. s.start((pos/1000));
  34. }
  35.  
  36. /*************************
  37. onLoad
  38. *************************/
  39. playSong("http://www.somesite.com/file.mp3");

Report this snippet  

You need to login to post a comment.