Articles Archive
Articles Search
Director Wiki
 

Detecting and Launching Audio CD Players

December 4, 2001
by Will Turnage

Dear Multimedia Handyman,

I'm creating a hybrid CD that will have audio on it that you can also play in a CD player. I want to add a button inside my program that will open up RealJukebox on the person's computer so they can listen to the audio. How do I do that? Thanks,

Kevin

Dear Kevin,

If you want to launch another program from your Director projector, then the first step is to find out the exact program you need to launch. In the case of a computer's CD player, you don't want to write your code to only look for RealJukebox (or WinAmp or any other specific CD player). The reason for this is that there are so many different programs on different computers that it's nearly impossible to account for them all. And then once a new version of the software is released, the code on your CD-ROM instantly becomes obsolete.

So how do you find which program is the default CD player on a user's computer? Well, you have to read the system preferences on their machine. In order to read those preferences, you need to use a third party Xtra, since Director does not have this capability built in. For the purposes of this article, we'll use two different system Xtras: BuddyAPI and DirectOS. Each of these Xtras are commercially available for both Mac and Windows which makes them ideal for your project.

To find the default CD player on a Macintosh, you can use the findapp function in either one of these Xtras. For instance, using BuddyAPI you could type:

put baFindApp("aucd")
-- "Will's iMac:Applications (Mac OS 9):AppleCD Audio Player €:AppleCD Audio Player"

or using DirectOS you would say:

put dosFindApp("aucd")
-- "Will's iMac:Applications (Mac OS 9):AppleCD Audio Player €:AppleCD Audio Player"

In each one of these examples, you pass the string "aucd" to the appropriate handler. On the Macintosh, this string is the Creator identification for audio CD files (you can use ResEdit or another disk-editing tool to identify this value). The Xtra takes that string, finds the application associated with it, then returns the full path to the default CD Audio player on that machine.

On Windows, though, you have to do something a little different. Windows doesn't associate its CD player application with a file extension. Instead, it stores the default application in its registry. If you look in your own registry, you can find the name of the application in the following branch:

\HKEY_CLASSES_ROOT\AudioCD\Shell\Play\Command\

Since you can't use the findApp function to get the information, you'll have to use another function from your Xtra to get the information. Using BuddyAPI, it would look like this:

put baReadRegString( "AudioCD\Shell\Play\Command\", "", "Error", "HKEY_CLASSES_ROOT" )
-- "C:\Program Files\Real\RealJukebox\realjbox.exe /play %1"

or using DirectOS you would say:

put dosReadReg("HKEY_CLASSES_ROOT", "AudioCD\Shell\Play\Command\", "")
-- "C:\Program Files\Real\RealJukebox\realjbox.exe /play %1"

And now you've got the full path to the default CD player on a Windows machine. When you put it all together, you can put this entire handler on a behavior on your button.

on mouseUp me
  if the platform contains "Windows" then
    cdAppPath = baReadRegString( "AudioCD\Shell\Play\Command\", "", "Error", "HKEY_CLASSES_ROOT" )
  else
    cdAppPath = baFindApp("aucd")
  end if
  open cdAppPath
end

This handler first checks to see if you're running on a Windows machine. If so, it looks up the path for the default CD player in the registry. If you're running on a Mac, then it finds the application associated with audio CDs. Once it has that path, then it opens the application using Director's built in open function.

Will Turnage is a multimedia programmer based in New York City. In addition to his weekly role as Director Online's Multimedia Handyman, he is also the Technology Director for Sony Music's Client Side Technologies Group. You can read more about his work at http://will.turnage.com/.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.