Results 1 to 2 of 2
Thread: Closing a clip
- 02-01-2012, 11:38 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 23
- Rep Power
- 0
Closing a clip
Hello, i have a big memmory leak in my program, and ive found the problem. But i cant seem to fix it correctly. Im making a towerdefence game, every tower has his own thread. Then as soon as the tower will shoot, it will play a sound. Here it goes wrong. I have to close my clip (otherwise my game will run out of memmory) but i have to close it only AFTER the sound is done. Here is my playSound function:
I have tried several solutions (clip.isOpen, clip.isRunning but nothing seems to solve my case)Java Code:private void playSound(String filename) { File soundFile = new File(filename); AudioInputStream sound = null; try { sound = AudioSystem.getAudioInputStream(soundFile); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat()); Clip clip = null; try { clip = (Clip) AudioSystem.getLine(info); } catch (LineUnavailableException e) { e.printStackTrace(); } try { clip.open(sound); sound.close(); } catch (LineUnavailableException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } clip.addLineListener(new LineListener(){public void update(LineEvent event){}}); clip.start(); try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } clip.close(); clip.flush(); }
Any help on closing the clip AFTER its done playing?
- 02-01-2012, 11:43 AM #2
Member
- Join Date
- Jan 2012
- Posts
- 23
- Rep Power
- 0
Similar Threads
-
java CLIP
By nikkka in forum New To JavaReplies: 0Last Post: 04-21-2011, 08:52 AM -
Fill in rectangle partially (clip?¿)
By OBLITERATOR in forum New To JavaReplies: 1Last Post: 03-07-2010, 04:59 AM -
sound clip
By f_the_cook in forum Advanced JavaReplies: 4Last Post: 10-17-2008, 05:19 PM -
How to Clip an Image
By Java Tip in forum java.awtReplies: 0Last Post: 06-23-2008, 11:24 PM -
How do i play an audio clip from a server?
By JavaJenius in forum NetworkingReplies: 1Last Post: 03-08-2008, 06:40 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks