Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Problem with playing sound files

Reply
Thread Tools

Problem with playing sound files

 
 
Christian Kremser
Guest
Posts: n/a
 
      03-08-2005
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.
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      03-09-2005
Christian Kremser wrote:
> 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.

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Playing sound files Ravi Java 8 04-08-2008 06:05 PM
Playing Sound Files fuli open HTML 4 03-26-2007 11:30 AM
No sound playing .swf files PackRat2112 Computer Support 0 08-19-2006 07:22 PM
Playing sound through non default sound card dkga_dkga@yahoo.com Java 0 03-05-2006 04:38 AM
Sound lost when playing AVI files Ron Clarke ASP .Net 0 02-24-2004 08:14 PM



Advertisments