• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Midi stop working

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, It s my first time here in this great forum! Hope someone help me please. It is a simpple code that works fine. Take a look below. It plays a note when the button is clicked! The problem is: When I put the midi part of this code in a separeted Class the midi note sounds 15 times and stop working!? I do not know why.I tried many thinks. I would like to put the midi part in a different class just to take advantage of oriented language. Thanks if anyone could help!

 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

I'm not familiar with how javax.sound works internally, but one thing that is definitely a problem with this code is that you're playing the sound from inside of the actionPerformed method. Event handlers should run (and terminate) quickly, lest they block other threads from running. So putting a Thread.sleep into an event handler is a big no-no. Start a new thread that plays the sound, and ses if that improves matters.

Since this is really not a beginner question, I'll move it to the Other Java APIs forum, where the Sound API is generally discussed.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!