Shvatz shows how Microsoft's Active Movie Control can make your audio and video do almost anything — even "The Thing."
Have you ever sat down and listened to computer music? Not music created on a computer, but music created by a computer? Probably not, huh? There's good reason for this - computers can easily handle the mathematical rules of music, but arranging said rules into a coherent and enjoyable song is another ballgame entirely. This is why software like Brian Eno's Koan Pro veers away from the rigid structure found in today's popular music in favor of a more Zen-inspired sonic environment. Sure, hits by the Spice Girls and Hanson may seem like they were written by machines, but chances are there was at least some human (or possibly alien) intelligence behind the curtain, calling the shots.
That said, I've gone and created my own bit of pseudo-generative music "software" for Microsoft Internet Explorer 4.0. Of course, it's pretty simple compared to some of the stand-alone packages, and yes, its output lacks a certain aesthetic je ne sais quoi, but occasionally there are flashes of brilliance for which I would gladly claim authorship. And, seeing as it will continue to play until you or your machine cries mercy, it can at least be called prolific if nothing else.
The Thing, as I've been calling it (for lack of a more creative name), uses HTML, javascript, and, most importantly, Microsoft's Active Movie Control, which is built into Microsoft Internet Explorer 4.0. The AMC has a somewhat misleading name, since it handles both audio and video, but never mind that; it's a damn fine control, and we're not going to let semantics stand in the way of our good time.
The Active Movie Control, in tandem with your favorite client-side scripting language, allows you to have great control over the properties of your sound and video. You can use it to do the basics, like telling the media to play, pause, or stop, as well as controlling more esoteric functions like changing the volume, panning (on stereo files), varying the speed at which the media play back, and changing the start and end points. You can even determine which elements of the control are visible to the browser, and whether or not their properties can be altered by the user.
What's more, the Active Movie Control will play back almost every file format under the sun. Supported types include AVI, MOV, WAV, MIDI, MPEG-layer1, layer2, and (in what could well be the most subversive gesture Microsoft has ever made) the file format of choice for Internet audio pirates around the world, MPEG3.
The music that The Thing currently makes could be classified as Jungle, or Drum & Bass. It uses a slightly modified version of perhaps the most widely known and (over-) used drum loop as its basis - the Amen. The Amen loop was culled from the R&B/gospel tune "Amen Brother" by the Winstons and has managed to work its way into perhaps thousands of songs in many styles of music. I used it here because I happen to have a licensed version taken from a sample CD, because it's instantly recognizable, and because I'm too lazy to grab one of my own beats off of my Mac and shuttle it over to my PC.
So, what does this all mean? Well, autostart requires a Boolean (true/false) value to determine if the media will play of their own accord, or if they require interaction from the user. A loop also requires a Boolean value to determine if the media loop back to the beginning when they reach the end, or if they just stop. Of course, src is just the pathname to the file, and you all know what that is, right?
Pretty straightforward, no?
The next way to invoke the Active Movie Control is through the image tag, oddly enough. This is specific to AVI files only, so its use is rather limited, but I figure it's a good thing to know just to impress your friends. Here's what the typical "image dynsource" tag (as it is called) should look like:
start and loop behave exactly like autostart and loop do in the embed tag, except that here we specify the Boolean values numerically: 1 is "true" and 0 is "false." dynsrc behaves just like src would in the embed tag - just slap in a pathname and go. Very easy. Almost ... too easy.
If you're paranoid like I am, the simplicity of the last two examples left you highly suspicious. How is it possible to get such behavior out of such simple HTML? Well, you can't, really. Both embed and img dynsrc (image dynamic source) are very simple ways to invoke the Active Movie Control, but all they really do is play back the media that they point to. They expose the sometimes clunky and real-estate-wasting user-interface controls of the AMC by default, which can often be a nuisance on smaller monitors. What we need is a way to do a little fine tuning, get rid of the interface elements that we don't need, and specify what the user can and can't change. To do this, we need the power of the object tag. First, a word of warning to our younger readers, the squeamish, persons with heart conditions, and pregnant women - the object tag can seem a bit grisly at first. But don't worry, it's akin to watching violence on television - remember how it once upset you, but after prolonged exposure it didn't seem so bad, and now you wonder how you ever got along without it? Ahhh, violence. Well, the AMC's a bit like that. To wit, here's an example of the object tag in full regalia, with tailfins:
OK, so it looks hairy at first glance, but if you look closer, certain parameters become obvious. And the good news is you don't have to specify every single parameter when you invoke the Active Movie Control, just the ones that you want to change from their default settings. Now, I have neither the inclination nor the time (my editor needs this on his desk tomorrow, dammit!) to explicitly detail each parameter, so let's arrange them into like-minded groupings.
First, there's the object tag itself. It is very important that you give your object an ID so that you can reference it later using javascript and the Document Object Model (DOM). Name it whatever you feel like, provided it's within your scripting language's namespace, and give the object an appropriate width and height if necessary. Most important, though, is to include the correct ClassID, which in this case is CLSID:05589FA1-C356-11CE-BF01-00AA0055595A. Every ActiveX control has a unique ClassID, and it is crucial that you get every character correct, or else the ActiveX control will not be invoked properly, and whatever you're building will simply not work. If everything checks out, then we're ready to move on.
Next, there are the parameters that control which elements of the user interface are visible:
Many elements will prove to be self-evident, although the difference between, say, ShowSelectionControls and EnableSelectionControls might seem a bit dodgy at first. The difference there is that showing something only makes it visible, while enabling it makes it useful (the caveat being that no UI element is going to be useful if you can't see it). Any parameter that begins with "Allow" signifies whether or not the end-user can adjust the UI for that element. Parameters that require Boolean values take -1 to mean true and 0 to mean false for some reason. Although I haven't really run in to any problems using 1 as true, I would recommend adhering to the party line as a safety precaution.
The next set of groupings is more straightforward and directly affects the media involved rather than just the user-interface elements:
This bunch is fairly apparent, isn't it? However, there are a few things I should mention. If the PlayCount parameter has a value of 0, it will loop. AutoRewind will set the play head back to the beginning of the media when it reaches the end point, which brings us to SelectionStart and SelectionEnd. These, of course, set the start and end points of the media. However, if you simply want your media to start at the beginning and play through their entirety, simply leave these parameters out. Balance sets the stereo pan of the media if they incorporate sound. The values for Balance fall between -10000 and 10000, with 0 as the center value. Of course, make sure you use a stereo sound source, or else you will find the results rather lackluster. Volume obviously adjusts the relative loudness of the media, with a range of -10000 to 0, where 0 is full-tilt, rattle-your-speakers loud. Rate controls the rate at which the media play back. A value of 1 will play back at the true speed of the media, while values of .2 (the lowest) or 2.2 (the highest) will play back very slowly and very quickly respectively. FileName - now, do I really need to tell you what that does?
The good news is that if you've been paying attention and you know a scripting language reasonably well, your work is almost done. It just so happens that the parameter names that I've outlined are also the properties you use to dynamically alter the Active Movie Control elements with javascript or vbscript. Pretty sneaky, eh? For instance, suppose you had an HTML element that, when clicked on, called the javascript function changeStuff(), which in turn caused a sound in your AMC (which we gave the ID mySound) to change its rate, decrease its volume, and adjust its start and end times. I'm assuming that I don't need to explain event handlers in depth, but, in short (for those of you who may be new to the joys of scripting), you would insert a chunk of text that looks like this into the HTML element that triggers the changes:
onclick="changeStuff()"
The function itself is also a pretty straightforward affair:
So, when you click on the appropriate bit of HTML, your sound should speed up rather dramatically, become fairly quiet, and play from a point two seconds into the sound for a period of one second. Provided, that is, that your sound is already playing. What if we had set AutoStart to 0, and all the UI elements to hidden, and turned off the ability for the end-user to access them? Well then you're screwed, right? Wrong! We've got a few built-in methods to do just the trick. The great thing is that they're very easy to understand as well, since they sound just like they should: run(), stop(), and pause(). We've also got a unique property that checks to see whether the sound is running, paused, or stopped - CurrentState. The CurrentState property has three different numerical values that signify these three states: 0 means that the player is stopped, 1 means it is paused, and 2 means the player is running. Therefore, we modify our code slightly, to look like this:
You get a page that behaves like this. You might have noticed the addition of a pause button in this example - I wanted you to be able to pause the sound (and change the CurrentState), so that when you clicked the other button again you would be able to hear the difference in playback rate, volume, and the relative start and end points.