downloads, code samples, and how-tos

Interesting bits and pieces built over the years, some of them in use on this site. "I made them myself" but much of them involved some repurposing and extending of work other people had done and put out into the public domain.

So in that same spirit, I'll give credit and post my improvements here, for the world to enjoy ;)

arsenal audio downloads & info
read the back story
arsenal audio started life as a Hayden Porter Remixolgy column for sonify.org. Of course, I couldn't leave well enough alone, so I began adding... and adding. The Golden Mean gave me the idea to use XML for the song list for the player, and somewhere else on the web I picked up the idea of using PHP to read through my mp3 folders and dynamically generate the XML. Here's that file.

So then I needed PHP to be able to read mp3 id3 tags to generate the XML for the song list. A search on the web turned up a number of options that were way too involved, so I wrote my own id3 tag reader (well, just the v2 tags - the v1 tags are straightforward enough and available many places on the web). No warranties expressed or implied, but it works for me, and if you want to try it, you can download it.

Then I wanted a shuffle function... and it should play continuously as you navigate the site... well, all that got incorporated too. Here's the .fla source file. Finally, I wanted pages in the music section of the site to be able to load songs into the player, which required some javascript. Most of this was garnered from one web site or another; the relevant functions are available below.

how it works
  • web page loads apAudio.swf. If there is data in the flash shared object (see below), it is used to fill the playlist and set playback variables.
  • if there is no shared object, apAudio loads songlist.php as an XML file to generate its song list
  • songlist.php looks through audio folders, reading id3 tags from any file with an .mp3 extension
  • back in apAudio, song list gets saved in an array. This array gets sorted alphabetically if shuffle is off, randomly if on
  • first song in the list begins loading, then playing when it has buffered enough. If shuffle state is changed, array is refiltered and reordered, starting with next song (so current song is not interrupted)
  • if user selects a song to play from one of the music pages, the current song pointer jumps to the selected song and loads it
  • if user navigates to another page, document.body.onunload is set to the saveSong javascript function, which tells apAudio to save current song data to a flash shared object (sort of like PHP session variables or browser cookies)

songlist.php: read contents of folders to generate xml file for arsenal audio
getid3.php: get id3 tags from mp3 files, first tries id3v2, then v1
arsenal audio: the flash source file for our audio player
javascript functions: to allow host page to play songs
var movie = "apAudio";

function getMovie(movieName) { // returns proper object reference
  if (window.document[movieName]) {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1) {
    if (document.embeds && document.embeds[movieName]) {
     return document.embeds[movieName];
    }
  } else {
    return document.getElementById(movieName);
  }
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
  // First make sure the movie's defined.
  if (typeof(theMovie) != "undefined") {
   // If it is, check how much of it is loaded.
    return theMovie.PercentLoaded() == 100;
  } else {
    // If the movie isn't defined, it's not loaded.
    return false;
  }
}

function playSong(title) {
  // frame 5 (here referenced as 4) gets new song index and plays it   m = getMovie(movie);
  if (movieIsLoaded(m)) {
    m.StopPlay();
    m.SetVariable("songTitle",title);
    m.GotoFrame(4);
  }
}

function saveSong() {  // on page unload, saves play vars in flash shared object
  m = getMovie(movie);
  if (movieIsLoaded(m)) {
    m.GotoFrame(9);
  }
}

function apAudio_DoFSCommand(command,params) {  // accepts messages from flash for debugging
  alert(params);
}

function fixFlash() {  // so IE doesn't give you that annoying "click to use control" message
  theObjects = document.getElementsByTagName("object");
  for (var i = 0; i < theObjects.length; i++) {
    theObjects[i].outerHTML = theObjects[i].outerHTML;
  }
}


abstract (that busy thing to the left) downloads & info
read the back story
abstract began, like so many things do, with a google search. I was looking for a little jazz (so to speak) for some of the music pages on the previous version of this site and thought some kind of slideshow with my abstract photos might work. I knew it was possible to do transitions in Internet Explorer but I wanted to work within web standards as much as possible so Flash seemed like the better option.

Lo and behold, Todd Dominey at Dominey Design had built a Flash slideshow and put it into the public domain (meanwhile he has improved upon it to the point where you don't need to mess with ActionScript and offered it for sale). Once again I couldn't leave well enough alone - just still images fading into one another seemed too... peaceful, I guess.

So I made it into a small window which behind which large images dance, all viewed through a colored filter to blend better with the site's, er, aesthetic. Once again images are loaded dynamically with a PHP-generated XML page. Finally I added a button to stop the madness if you find it too distracting (one could argue it's like using blinking text).

how it works
  • web page loads abstract.swf.
  • abstract loads abstract.php as an XML file to generate its image list
  • abstract.php looks through image folder, making an entry for files with .jpg extension
  • back in abstract, image list gets saved in an array, sorted either randomly or sequentially (this is specified in the XML file)
  • first image in the list loads, assigning itself a movement pattern at random
  • next image loads, and first image fades into second
  • images continue loading and transitioning
  • stop button stops movements and image loading (possible bug: may need to clicked more than once)


abstract.php: read contents of folders to generate xml file
abstract: the flash source file


other interesting things
jQuery is a very cool javascript library that powers many of the visual effects on this site - various Flash-like effects, without having to use Flash. And a very simple AJAX framework. I'm sold, where do I sign up?!
audio site design site site map services web sites graphic design 3d / cg photography contact
tel: 781 656-2160