Re: Silly URL...



Joan <Joan@xxxxxxxxxxxxxx> wrote:
> I was just looking into "file chooser" and my book has an example
> of how you can add buttons to the file chooser to play an audio
> clip after you select it. The sample code uses URL to access the
> files on the local disk. I think it is needed in this case in
> order to use the audio methods.

No, I don't think you are correct. The only connections between audio
APIs and sound are:

1) The Applet class has a getAudioClip that requires a URL. However,
you almost certainly don't have an applet anyway, if you are accessing
files on the local hard drive.

2) The JavaSound API has a couple API methods that can receive URLs to
specify the locations of sounds. These are MidiSystem's
getMidiFileFormat, getSequence, and getSoundBank, and AudioSystem's
getAudioFileFormat and getAudioInputStream. However, all of these APIs
also have identical overloaded functions that use File instead of URL.

So I'm pretty sure you don't need a URL. However, if you do, then the
best way to go is to get a File object first, and then say:

File file; // the file object you start with
URL url = file.toURI().toURL();

Then yes, you are perfectly fine using the URL to refer to files on the
local disk. This is actually guaranteed to work, as all Java virtual
machines are required to support the URL scheme for accessing local
files. However, since the exact syntax is platform-specific, the
conversion methods above are your best bet here.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
.