Member Avatar for Member #161929

I'm currently working on one of my first full website projects and i need to have a flash music player included. So far I've made basic scripts to make the play, stop, and pause buttons work, but the player can only load one song. I'm hoping that the finished flash player will be able to load multiple songs via next and previous buttons, and that song information (possibly from ID3 tags?) can be displayed within the player as the song changes. If anyone could help me to write (or even better, understand) the code i would greatly appreciate it.

Dani AI

Generated

A quick note for and anyone else rebuilding a simple Flash jukebox from that era: the cleanest, most reliable pattern is to keep the playlist and display metadata in an external data file (XML or JSON) and let the SWF load that file at runtime. Store title/artist in the playlist so the UI updates instantly, and treat ID3 as an optional fallback (ID3 arrives asynchronously after a partial MP3 download and can be inconsistent across encoders).

Example playlist XML (simple, absolute URLs recommended if hosted separately):

<playlist>
  <track>
    <url>http://example.com/music/song1.mp3</url>
    <title>Song One</title>
    <artist>Artist Name</artist>
  </track>
  <track>
    <url>http://example.com/music/song2.mp3</url>
    <title>Song Two</title>
    <artist>Artist Name</artist>
  </track>
</playlist>

Core ActionScript 2 workflow (concise): load the XML, parse into an array of track objects, create a Sound instance, and implement playTrack(index), next() and prev() that call loadSound(...) for the selected URL. Attach an onID3 handler to the Sound to inspect any ID3 fields and update UI if you want to show tag data when it becomes available. Example parsing & play skeleton (AS2-style):

var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function(success) {
  if (!success) { trace("XML failed"); return; }
  var playlist:Array = [];
  var tracks = this.firstChild.childNodes;
  for (var i:Number=0; i<tracks.length; i++) {
    var t = tracks[i];
    playlist.push({
      url: t.childNodes[0].firstChild.nodeValue,
      title: t.childNodes[1].firstChild.nodeValue,
      artist: t.childNodes[2].firstChild.nodeValue
    });
  }
  // call playTrack(0) etc.
};
xml.load("http://example.com/playlist.xml");

Troubleshooting & tips: if the XML or MP3s are on another domain you must serve a permissive crossdomain.xml from that host or test from an HTTP server (Flash local-file security blocks remote loads). For local testing use a local webserver (XAMPP, etc.) or the Flash Player global security settings. Passing a playlist URL into the SWF via FlashVars lets the same SWF load different playlists without republishing. Storing metadata in the playlist XML avoids dependence on ID3 timing and gives the best UX.

Recommended Answers

All 3 Replies

Member Avatar for Member #114696

I dont whether its in other versions but there is sample jukebox in sample apps in MX 2004. That would give you a drift.

You see that's not a big deal. You have two option, use XML or PHP. You could even give arguments to swf file. http://www.daniweb.com/forums/thread58249.html

That would help when you use PHP.

For sound you must be surely using sound object. For getting ID3 tags use sound.id3.

use your actionscript reference which is of course include with your copy of flash to know what these two things do.

Member Avatar for Member #161929

ok well i got a player up and running, but i need to know if there is a way to link the xml file with a web address, because as of right now, i cannot upload either to my server, and thus, the xml cannot be in the same folder as the flash file.

Member Avatar for Member #161929

never mind stupid question =p

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.