Problem with playing sound files

  • Thread starter Christian Kremser
  • Start date
C

Christian Kremser

I have a problem with playing sound-files (wav-files) from my
application. The application should play a short (about 1-2 sec
long) sound-file (the existence of the files ich checked) from a
list each time the user pushes a button (the index of the list is
changed for each button press). The problem I have is, that it
sometimes works and plays the sound and sometimes it doesn't play
the sound and there is now error thrown. The part of my code
which plays the sound is as follows:

try {
URL completeURL = new URL("file:" +
FileList[actIndex]);
AudioClip audioClip = Applet.newAudioClip(completeURL);

audioClip.play();
} catch (MalformedURLException e) {
System.err.println(e.getMessage());
}

Has anybody an idea what is wrong with this? How can I make sure
ensure that the file is completely loaded and ready for playing
(if (audioClip==null) didn't bring any improvement)? Or, how can
I determin if the AudioClip has finished playing?

Thanks in advance for any help!
Cheers,
Christian.
 
K

Knute Johnson

Christian said:
I have a problem with playing sound-files (wav-files) from my
application. The application should play a short (about 1-2 sec long)
sound-file (the existence of the files ich checked) from a list each
time the user pushes a button (the index of the list is changed for each
button press). The problem I have is, that it sometimes works and plays
the sound and sometimes it doesn't play the sound and there is now error
thrown. The part of my code which plays the sound is as follows:

try {
URL completeURL = new URL("file:" + FileList[actIndex]);
AudioClip audioClip = Applet.newAudioClip(completeURL);
audioClip.play();
} catch (MalformedURLException e) {
System.err.println(e.getMessage());
}

Has anybody an idea what is wrong with this? How can I make sure ensure
that the file is completely loaded and ready for playing (if
(audioClip==null) didn't bring any improvement)? Or, how can I determin
if the AudioClip has finished playing?

Thanks in advance for any help!
Cheers,
Christian.

Christian:

I've seen the error too on Windows machines. I don't know how to solve
it other than trying to use the Clip interface instead of AudioClip.
The problem appears to be more pronounced if you are playing one
AudioClip right after another and it may be a browser problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top