• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Midi stop working

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Those are the largest trousers in the world! Especially when next to this ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic