Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Questions about Clip management  (Read 1342 times)
0 Members and 1 Guest are viewing this topic.
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Posted 2005-01-29 22:07:35 »

Currently when I load my clips I call this:
1  
2  
3  
4  
5  
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(audioFormat, audio, 0, size);
clip.stop();
clip.flush();
clip.close();

So that the Clip is loaded into memory and won't lag before playing the first time I call for it.  This works fine on Windows and Linux, but on Mac's it makes little clicking sounds like it's playing the beginning of each clip.  Is there a better way to do this?

Also, can I reuse Clips?  Right now the biggest thing making the allocations build up so that the GC gets called frequently is my use of Clips.  I want to be able to hold on to a Clip and tell it to .start() again later or something so that I don't have to create a new one.

To try this I take that first clip and call:
1  
2  
3  
4  
if (!clip.isOpen()) {
       clip.open(audioFormat, audio, 0, size);
}
clip.start();

However this doesn't seem to work.  If this is possible, what do I need to do to reuse my Clips?

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline MasterOfDisaster

Junior Member




O_o


« Reply #1 - Posted 2005-01-30 06:02:41 »

not sure if i understand you right. all you want to do is load some clip and play it multiple times, right?
i do it this way:

public void play() {
       if (soundEnabled) {
           if (!clip.isRunning()) {
               clip.setFramePosition(0); // rewind the clip
               clip.start();
           }
       }
   }

// for looping sounds
public void startLoop() {
       if (soundEnabled) {
           if (clip.isRunning()) {
               clip.stop();
           }

           clip.setFramePosition(0); // rewind the clip
           clip.loop(Clip.LOOP_CONTINUOUSLY);
       }
   }

regarding the click sounds:
i always get them (on my windows machine) when i call close() or flush(). i decided not call them any longer. i load all clips at the startup of the game, keep them in memory, use the above methods to play them and let the environment system do the cleanup when the application exits. this is probably not the best way, but it works best for me.

Offline MasterOfDisaster

Junior Member




O_o


« Reply #2 - Posted 2005-01-30 06:04:06 »

aaah, sorry for not using the [code] tags ... :-/

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #3 - Posted 2005-02-03 03:47:51 »

Thanks for that!  I thought that was what I was doing... so I must be missing something Smiley  At least I know how to do it right though, thanks!

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #4 - Posted 2005-02-16 22:42:34 »

Everything works great now Smiley

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (37 views)
2014-07-18 06:55:21

Zero Volt (35 views)
2014-07-17 23:47:54

danieldean (28 views)
2014-07-17 23:41:23

MustardPeter (31 views)
2014-07-16 23:30:00

Cero (46 views)
2014-07-16 00:42:17

Riven (47 views)
2014-07-14 18:02:53

OpenGLShaders (36 views)
2014-07-14 16:23:47

Riven (36 views)
2014-07-14 11:51:35

quew8 (32 views)
2014-07-13 13:57:52

SHC (69 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!