Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 Re: Coder's Corner » Java sound solution » 2008-05-01 17:44:40

This is what I am doing for sound, it loads each file at the start but my problem is that if I try to load too much I get an error.
java.lang.OutOfMemoryError: Java heap space

//initialization
AudioClip soundTokyo;
AudioClip soundGame;
URL u = RiskCanvas.class.getResource( "music\\livefromkyoto-moonless-dawn.wav" );
	      if ( u == null )
	         {
	         throw new IllegalArgumentException ( "music file missing" );
	         }
	      soundTokyo = getAudioClip( u );
	      u = RiskCanvas.class.getResource( "music\\trip-warhawkins-stolen-gamecube.wav" );
	      if ( u == null )
	         {
	         throw new IllegalArgumentException ( "music file missing" );
	         }
	      soundGame = getAudioClip( u );
//====================================================================
//when I go to play one I make sure the other is stopped and start looping the next
if()
soundGame.stop();
soundTokyo.loop();
else
soundTokyo.stop();
soundGame.loop();

Right now I am using it play background music that the user can pick from in a menu. But if I can't find a way to load them without error, I might have to use it for sound effects instead of the large wav files I am currently using.

Board footer

Powered by FluxBB