|
-
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()
{
}
}
-
April 1st, 2009, 01:50 AM
#2
Re: Small problem trying to play a wav file?
It depends on the type of your operating system.
Try to use classes in package javax.sound.sampled, for example, AudioSystem, instead of java.applet.*.
-
April 1st, 2009, 03:03 AM
#3
Re: Small problem trying to play a wav file?
i am using windows vista, 64 bit... I have been told that i have to do it the way i am currently approaching the problem, as part of the assignment. thanks for your help though.
-
April 1st, 2009, 12:39 PM
#4
Re: Small problem trying to play a wav file?
can anyone help me? thanks in advance...
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
|