• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't play sound clip a second time  RSS feed

 
Joe Areeda
Ranch Hand
Posts: 334
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working out some issues with a practice program that displays a clock. I want to add chimes. I did say I'm learning some things I haven't done before.

My problem is the program plays the sound from a resource just fine the first time but subsequent tries produce the error:



Which doesn't make sense to me because it is supported exactly once. Which makes me believe I should be closing, resetting or destroying something but I can't figure out what.

Here's the snippet, I got it from several places when reading up on the task:



I did add the bit about closing the input stream and setting the FramePosition but that didn't seem to help or hurt.
I do need to play different sounds in the real applicaiton so keeping the clip and just resetting the position is not what I want to do.

I'd appreciate any insight into what I'm missing or a link to read up on it.

Thanks,
Joe

 
Joe Areeda
Ranch Hand
Posts: 334
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to be the Clip object which has to closed. After a bit more reading and some tweaking this version seems to work repeatedly.



Sometimes it helps to try to explain things clearly enough to ask for help.

Thanks for being here.

Joe
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are looking for some possible tweaks - one I would suggest is not waiting for the clip to be called again before closing, rather - add a LineLister to listen for when the clip is finished playing, then close it:



Another thing to avoid is the simple System.err.println(e.getMessage()); There is a lot more information available for example the code location where the error occurs, and the call chain which cause the exception) if you do e.printStackTrace();
 
Joe Areeda
Ranch Hand
Posts: 334
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve!

I was just looking into how to do that.

Oh and the print error was just for the example in real life the exception gets passed back and properly logged.

Best,
Joe
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you let an app loose in the big wide world, however, you would probably change your exception handling to log things in a file back at your own server. The stack trace will be completely incomprehensible to the end user.
 
Joe Areeda
Ranch Hand
Posts: 334
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:If you let an app loose in the big wide world, however, you would probably change your exception handling to log things in a file back at your own server. The stack trace will be completely incomprehensible to the end user.


I agree. That is a topic worthy of its own thread. I'll collect my questions, doubts and insecurities on how I do it now and start one later today.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!