Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °
| |
|
|
You are not logged in.
Post a replyTopic review (newest first)
Also you can tinker with port 61, the old PC speaker!!
Always go to the source...
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. Code://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.
anyway, i seemed to have resolved the issue by resorting to string comparisons for array processing. I don't like doing this but it seems to be the easiest way out. I wonder if string comparison really takes as long as i fear...
i believe that doesn't work if, for instance, b were a subclass of ball.
Don't quite see what exactly the problem is. You can just use the Class.forName method:
The problem is the first time it plays, it has to load the sound file from the system, which takes a moment. i'd really rather do it at game creation rather than play time. Otherwise, like i said, the game pauses briefly every time a new sound plays.
The code you posted looks like it should work just fine. Why is it that you have to play a sound when the program starts up to not cause a delay later?
in the meantime, here's another problem concerning java that i've just been faced with. I figured i'd post it here rather than making a new thread for every problem i run into.
two other methods i used had a built in sound player which pretty much hid the details, it just said playSound(file) so i don't think it there's any point in posting those. Code:import java.io.*;
import sun.audio.*;
public class AudioStreamPlay
{
// AudioPlayer instantiated to force run of static initializers.
private AudioPlayer audioPlayer = AudioPlayer.player;
private AudioDataStream audioDataStream;
private ContinuousAudioDataStream continuousAudioDataStream;
// Applet role
public void AudioStreamPlay()
{
try
{
// Get sound from file stream.
FileInputStream fis = new FileInputStream( new File( "soundFile.au") );
AudioStream as = new AudioStream( fis ); // header plus audio data
AudioData ad = as.getData(); // audio data only, no header
audioDataStream = new AudioDataStream( ad );
continuousAudioDataStream = new ContinuousAudioDataStream( ad );
}
catch (Exception exp)
{
System.out.println("error! x_x");
}
}
// Component role (1.02 event model)
public void playSound()
{
audioPlayer.start( audioDataStream );
}
public void loopSound()
{
audioPlayer.start( continuousAudioDataStream );
}
public void stopSound()
{
audioPlayer.stop( audioDataStream );
audioPlayer.stop( continuousAudioDataStream );
}
public void resetSound()
{
continuousAudioDataStream.reset();
}
}
import java.io.*;
import sun.audio.*;
public class AudioStreamPlay
{
// AudioPlayer instantiated to force run of static initializers.
private AudioPlayer audioPlayer = AudioPlayer.player;
private AudioDataStream audioDataStream;
private ContinuousAudioDataStream continuousAudioDataStream;
public void AudioStreamPlay()
{
try
{
// Get sound from file stream.
FileInputStream fis = new FileInputStream( new File( "soundFile.au") );
AudioStream as = new AudioStream( fis ); // header plus audio data
AudioData ad = as.getData(); // audio data only, no header
audioDataStream = new AudioDataStream( ad );
continuousAudioDataStream = new ContinuousAudioDataStream( ad );
}
catch (Exception exp)
{
System.out.println("error! x_x");
}
}
public void playSound()
{
audioPlayer.start( audioDataStream );
}
public void loopSound()
{
audioPlayer.start( continuousAudioDataStream );
}
public void stopSound()
{
audioPlayer.stop( audioDataStream );
audioPlayer.stop( continuousAudioDataStream );
}
public void resetSound()
{
continuousAudioDataStream.reset();
}
}
Can you paste the code snippets which are used for loading and playing sounds?
Use Flash ... SwishMax version 2 is currently in beta testing, and worth looking at when it is released.
i have yet to find ANY workable solution to add sound effects to a game written in java. |