3 Replies Latest reply on Feb 17, 2008 5:20 PM by kglad

    mp3 radio player help

    Lotar_vk
      Hi there!

      I'm kind of new with actionscript and would really appriciate any help. The thing is that I'm trying to create a flashmp3 radio, and I cant get it right. When I play mp3 files through that player, it works just fine, but only on localhost... When I upload it, browser eats whole ram that i have, wich is 1GB by the way, and song isn't even played. Just to mention I try to stick with actionscript 2. So if anyone knows what to do, I would be wery gratefull.

      You can see it "live" here (warning, it could crash your browser): www.mladen-lotar.net/player/player.swf

      And here's the "main code":

      //MOVIE PROPERTYS
      Stage.scaleMode = "noScale";
      _soundbuftime = 20;

      //VARIABLES
      var cue:Number = 0;
      var inc:Number = 0;
      var current_song:Number = 0;
      var next_song:Number = 0;
      var genre_p:String = "hip hop";
      var format = genre_txt.getTextFormat();
      var sound:Sound = new Sound();

      var song:Array = new Array();
      var genre_arr:Array = new Array();
      var artist_arr:Array = new Array();
      var title_arr:Array = new Array();

      //MAIN (loading xml file)
      var songList_xml:XML = new XML ();
      songList_xml.ignoreWhite = true;

      songList_xml.onLoad = function (success)
      {

      if (success)
      {
      var k:Number = -1;
      var gnr:String;
      var gnr_tmp:String;
      for (var i=0; i<songList_xml.firstChild.childNodes.length; i++)
      {
      song = new Array();
      genre_arr
      = new Array();
      artist_arr = new Array();
      title_arr
      = new Array();

      gnr_tmp = songList_xml.firstChild.childNodes .attributes.genre;

      if (gnr == gnr_tmp)
      {k++;}
      else
      {gnr=gnr_tmp;k=0;}

      genre_arr[k][gnr] = songList_xml.firstChild.childNodes
      .attributes.genre;
      artist_arr[k][gnr] = songList_xml.firstChild.childNodes .attributes.artist;
      title_arr[k][gnr] = songList_xml.firstChild.childNodes
      .attributes.title;

      song[k][gnr] = songList_xml.firstChild.childNodes .attributes.url;
      }
      }

      //DISPLAY LOADING
      displayPercent = function ()
      {
      track_status.alpha = 30;
      track_position._alpha = 0;
      var percent = (sound.getBytesLoaded()/sound.getBytesTotal()*100);
      track_status._width = percent * 4.01;
      if (sound.getBytesLoaded() == sound.getBytesTotal())
      {
      track_status.alpha = 30;
      track_position._alpha = 0;
      alpha1 = setInterval(al1, 100);
      clearInterval(timer);
      }
      };
      timer = setInterval(displayPercent, 100);

      al1 = function ()
      {
      if (track_status._alpha > 0)
      {track_status._alpha -= 5;}
      if (track_position._alpha < 100)
      {track_position._alpha += 10;}
      if (track_position._alpha == 100 and track_status._alpha == 0)
      {
      clearInterval(alpha1);
      }
      };
      alpha1 = setInterval(al1, 100);

      var percent2:Number;
      displayPosition = function ()
      {
      percent2 = ((sound.getPosition()/sound.getDuration()))*100;

      track_position._width = percent2 * 4.01;
      track_txt.text = track_position._width;

      if (sound.getPosition() == sound.getDuration())
      {
      clearInterval(display_position);
      }
      };
      var display_position = setInterval(displayPosition, 100);

      //TRACK POSITION
      trackPosition = function ()
      {
      Inc = function ()
      {
      cue = sound.getPosition() / 1000;
      //trace ("Cue:" + cue + " Duration:" + sound.getDuration()/1000);

      //(sound.getDuration() / 1000)
      if (cue >= (sound.getDuration() / 1000))
      {
      track_status._alpha = 30;
      track_position._alpha = 0;

      sound.start();

      current_song++;

      if (song[current_song][genre_p] == null)
      {current_song = 0;}

      playSong(current_song);
      }
      };
      position = setInterval(Inc, 100);
      }

      //PLAY SONG
      function playSong(current:Number)
      {
      clearInterval(display_position);
      clearInterval(position);
      clearInterval(timer);
      clearInterval(alpha1);

      sound.loadSound(song[current_song][genre_p], true);

      timer = setInterval(displayPercent, 100);

      position = setInterval(Inc, 100);

      genre_txt.text = genre_arr[current_song][genre_p];
      genre_txt.setTextFormat(format);
      artist_txt.text = artist_arr[current_song][genre_p];
      artist_txt.setTextFormat(format);
      track_title_txt.text = title_arr[current_song][genre_p];
      track_title_txt.setTextFormat(format);
      sound.start(0,1);
      trackPosition();

      sound.onLoad = function()
      {
      display_position = setInterval(displayPosition, 100);
      }
      }

      var num:Number = 0;
      for (var i = 0; i < song.length; i++)
      {
      if (genre_p == genre_arr
      [genre_p])
      num++;
      }
      current_song = random(num);

      clearInterval(display_position);
      clearInterval(position);
      clearInterval(timer);
      clearInterval(alpha1);

      sound.loadSound(song[current_song][genre_p], true);

      timer = setInterval(displayPercent, 200);
      position = setInterval(Inc, 200);

      genre_txt.text = genre_arr[current_song][genre_p];
      genre_txt.setTextFormat(format);
      artist_txt.text = artist_arr[current_song][genre_p];
      artist_txt.setTextFormat(format);
      track_title_txt.text = title_arr[current_song][genre_p];
      track_title_txt.setTextFormat(format);

      sound.start(0);
      trackPosition();
      sound.setVolume(30);

      sound.onLoad = function()
      {
      display_position = setInterval(displayPosition, 200);
      }
      };

      songList_xml.load("radio_list.xml");