|
-
March 31st, 2009, 07:10 PM
#1
Small problem trying to play a wav file?
This code seems to compile properly without any errors, and when i run it, it displays a frame, without a problem, as you can see i may be over complicating this by using threads, but thats because this project will eventually turn into a multi-threaded pacman game (for university assignment)
anyway, the code compiles, and a frame appears, there is not a null pointer exception, so im guessing my application can "see" the wav file in its directory, but theres no sound... any ideas?
oh and by the way, the random generator doesn't do anything, its just left in there from an experiment...
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.AudioClip;
import java.net.URL;
import java.util.Random;
public class PacMan implements Runnable
{
private final static Random generator = new Random();
private JFrame frame;
public static void main(String[]args)
{
Thread CreateGui = new Thread(new PacMan());
CreateGui.start();
}
public PacMan()
{
frame = new JFrame("Test PacMan");
frame.setSize(500,500);
frame.setVisible(true);
playAudioResource("pacman_intro.wav");
}
public void playAudioResource(String AudioResourceName)
{
ClassLoader cl = PacMan.class.getClassLoader();
URL resourceURL = cl.getResource(AudioResourceName);
AudioClip sound = JApplet.newAudioClip(resourceURL);
sound.play();
}
public void run()
{
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|