Results 1 to 3 of 3
Thread: Sound i Java Application
- 01-11-2013, 09:51 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
Sound i Java Application
Hi, I am trying to add sounds to my simple game in Java. The code looks like:
And it doesn/t work. I get an error:Java Code:import java.io.File; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; . . . . public void setHit() { if(!hit) { hit=true; playSound(new File("sounds/balloon_boom.wav")); } }
What am I doing wrong and how I can "fix" it?Java Code:error: cannot find symbol playSound(new File("sounds/balloon_boom.wav")); symbol: method playSound(File) location: class Menu
Best regards
//mistake in topic ;/
- 01-11-2013, 10:41 AM #2
Member
- Join Date
- Dec 2012
- Posts
- 74
- Rep Power
- 0
Re: Sound i Java Application
Whenever you call a method, you need to prefix the method name with an object or a class name.What am I doing wrong and how I can "fix" it?
object.playSound();
or
ClassName.playSound(); // for a static method
The only time that you could call a method without prefixing it with an object or a class name is if you defined that method in the current class which isn't the case here.
I did get the following code to work:
Java Code:import sun.audio.*; //import the sun.audio package import java.io.*; public class Sounds { public static void main(String[] args) throws IOException { // Open an input stream to the audio file. InputStream in = new FileInputStream("pop.wav"); // Create an AudioStream object from the input stream. AudioStream as = new AudioStream(in); // Use the static class member "player" from class AudioPlayer to play clip. AudioPlayer.player.start(as); } }
- 01-11-2013, 02:18 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Java Sound
By cyberia in forum Advanced JavaReplies: 2Last Post: 08-19-2011, 12:58 PM -
Problems with sound in java and USB sound card
By marblecatdog in forum New To JavaReplies: 1Last Post: 04-19-2011, 12:02 PM -
Make sound play in a java application
By lenny in forum AWT / SwingReplies: 2Last Post: 08-13-2007, 11:45 AM -
Error: Can't run as an application since it use sound-related methods
By mathias in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:45 AM -
MMAPI sound application
By luisarca in forum CLDC and MIDPReplies: 0Last Post: 06-18-2007, 06:34 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks