How To Loop A Sound

Sep 24, 2014

I created a game but want some music in it, and as I write in the title i want the sound to loop. This is the code fore the sound class i have:

Java Code:

import java.applet.Applet;
import java.applet.AudioClip;
public class Sound {
private AudioClip clip;
//all sounds
public static final Sound ScoreSound = new Sound("/Score.wav");
public static final Sound BounceSound = new Sound("/Bounce.wav");

[code].....

View Replies


ADVERTISEMENT

How To Get Sound To Import It To Game

Apr 7, 2015

how to make a simple game. I am having trouble when it comes to adding sound though. It tells me to do this:

package net.game.Game;
 
import java.applet.Applet;
import java.applet.AudioClip;
 public class Sound {
public static final AudioClip BALL = Applet.newAudioClip(Sound.class.getResource("ball.wav"));
public static final AudioClip GAMEOVER = Applet.newAudioClip(Sound.class.getResource("gameover.wav"));
public static final AudioClip BACK = Applet.newAudioClip(Sound.class.getResource("back.wav"));
}

What this does is it gets the sound file then gives it a name(BALL=ball.wav GAMEOVER=gameover.wav ect..) and then there is other code in other classes that call the sound so it will run but it keeps giving me an error and I don't know what to do. How can I get it to import the sound? Here is the error.

PHP Code:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at net.game.Game.stuff.<init>(stuff.java:35)
    at net.game.Game.stuff.main(stuff.java:62)
Caused by: java.lang.NullPointerException
    at sun.applet.AppletAudioClip.<init>(Unknown Source)
    at java.applet.Applet.newAudioClip(Unknown Source)
    at net.game.Game.Sound.<clinit>(Sound.java:7)
    ... 2 more 

View Replies View Related

Speed Of Sound Program

Feb 11, 2015

I have to write a program that asks the user to enter "air", "water", or "steel", and the distance that a sound wave will travel in the medium. The program should then display the amount of time it will take. The amount of time it takes sound to travel in air can be calculated as follows;

Time = Distance/1,100

The amount of time it takes sound to travel in water can be calculated with the following formula:

Time=Distance/4,900

The amount of time it takes sound to travel in steel can be calculated with the following formula:

Time=Distance/16400

Here is my code:

import java.lang.String;
/**
This program displays numbers padded with leading zeros.
*/
 
public class SpeedofSound {
public static void main(String[] args) {
double D; // declares this as double
D = keyboard.nextDouble();
 const double A = 1100; // declares this as a constant

[Code] .....

The following is the error I'm getting:

----jGRASP exec: javac SpeedofSound.Java
error: Class names, 'SpeedofSound.Java', are only accepted if annotation processing is explicitly requested
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

View Replies View Related

How To Synthesize Simple Sound

Sep 15, 2014

Okay, so I'm looking for a way to synthesize sound, and from what I've found around the interwebs it seems amazingly complex. Is there really not a function like "sound(wavelength, time)"? Alternatively a way to use an integer array to determine the acoutstic pressure at a given time, or some other way to determine the pressure at a given time?

View Replies View Related

Speed Of Sound Java

Jul 27, 2014

I can't get the output to read correctly. I get 0 as the answer.

import java.util.Scanner;
public class TheSpeedofSound777
{

public static void main(String[] args)
{

System.out.println("Gordon Elam Sr July 26, 2014 ");

[code]...

View Replies View Related

Play Pause Sound In Java?

Jan 15, 2015

What I want to do is very clear, just play sound and pause it. The problem is that I can't pause the music. When I click the pause button music keeps playing .I have been working on for 2 hours. I can't find the mistake; what am I doing wrong?

public class MainC extends JFrame implements Runnable,ActionListener {
private JPanel contentPane;
private JTextField txtname;
JButton btnopen;
JButton btnSave;
JButton btnplay;

[code]....

View Replies View Related

Play A Sound When Button Is Clicked?

Mar 20, 2014

im trying to play a sound when button is clicked. here is the following code

InputStream in;
try {
in = new FileInputStream(new File("failure1.wav"));
AudioStream audios = new AudioStream(in);
AudioPlayer.player.start(audios);
} catch (Exception e) {
}

just wondering why it does load;

i do get the warning

warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioPlayer is internal proprietary API and may be removed in a future release
AudioPlayer.player.start(audios);

View Replies View Related

Sound Clip Using Mediatools Class Will Not Play

Oct 5, 2014

I wrote the below program to set up and play the game breakout as an assignment for Stanford's CS106 programming class. I wrote it on my old mac running OSX 10.6.8, with the version of Eclipse JDK that works on that machine. When I tested it back on the mac, the program worked normally. But now I am using a Windows 8.1 computer with the corresponding version of eclipse, and when I test the program again, the sound effect I coded does not play. I get the following error message in console when the ball hits the paddle or brick, which previously caused the sound clip to play.

Exception in thread "Thread-4" java.lang.IllegalArgumentException: Requested value -120.0 smaller than allowable minimum value -80.0.
at javax.sound.sampled.FloatControl.setValue(Unknown Source)
at com.sun.media.sound.DirectAudioDevice$DirectDL$Gain.setValue(Unknown Source)
at acm.util.SoundPlayer.setLineVolume(SoundClip.java:909)
at acm.util.SoundPlayer.run(SoundClip.java:860)
at java.lang.Thread.run(Unknown Source)

why my code would request a value below the min. I am using the mediatools class that is part of the ACM libraries we are required to use for the class to play the sound in question, found here: URL....I went ahead and tested all parts of the program and the missing sound effect is the only problem. Here is my complete code:

package Breakout_package;

import acm.graphics.*;
import acm.program.*;
import acm.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

[code]....

View Replies View Related

Using Integer Array To Call Sound Samples

Nov 28, 2014

trying to get into Java and jump into just programming an idea.I want to go through an array of numbers at a certain pace and call different sounds as it goes through.

View Replies View Related

Receive Data From Midi Device With Java Sound API

Mar 15, 2014

I haven't been able to find a cut and paste working example of how to receive MIDI data from a MIDI device, like my piano, and display something to System.out.There are all sorts of examples for synthesizers, sequencers and sending data to a MIDI device, but I have not been able to find a single example of how to receive MIDI data and just display a simple message.

I just need something simple that works to start playing with it, and understanding how it works. Having a working example would also support understanding the Sound API descriptions. They read like differential equations texts books to me, i.e. not clear at all.

I have a working example of how to poll all devices and getDevice.info, which is supposed to then be used to address a specific MIDI device.

I've also looked at a number of books, in the store and on line.I haven't seen a single example anywhere.the closest I found to working examples was on StackOverflow, but I didn't understand some of the other code in the examples, which may or may not have been working correctly anyway.

View Replies View Related

Using Primitive Data Types To Overload Sound Method

Jun 29, 2014

Trying to find a way to use primitive data types to overload sound()method. I can't seem to warp my head around using an int or a double to overload the method. And if I did, how do you call them in the main afterwards?

View Replies View Related

Sound Won't Play When Player Dies And A Game Over Screen Pops Up

Jan 14, 2014

I am making a game with java in a program called greenfoot.My problem is that a sound won't play when the player dies and a Game Over screen pops up..

- I have saved the audio file in my sound map of the scenario
- Applied the good name of the file
- tested the sound effect and it's working

this is my code:

public GameOver()
{
setImage(new GreenfootImage("GAME OVER", 100, Color.BLACK, null));
Greenfoot.playSound("fail-trombone-03.wav");
Greenfoot.stop();
}

View Replies View Related

Applets :: Accessing External Resources - Play Particular Sound Whenever Button Is Pressed

May 4, 2014

I am quite new to developing Applets in java. I recently made an applet that will play a particular sound whenever a button is pressed. The sound files are placed in the same directory as the applet class file and i access them by using

AudioClip clip=getAudioClip(getCodeBase(),"A.wav").

The Applet runs fine in the appletviewer but whenever I try to open it using any browser like Chrome,IE,Firefox the applet loads but sound isn't played. I checked the java console and it showed

"java.security.AccessControlException: access denied ".

My questions are:

1. How do I allow the applet to get access to those files?

2. When the Applet is running from the local file system why CAN NOT I access those resources via getCodeBase() ???

3. I googled and found that I can sign a JAR and that can have full access to the computer. But how do I create a JAR from an applet (which has no Main method) while it asks me to point to the main class in the manifest?

View Replies View Related

Unable To Print A Loop Inside Array Of Greater Size Than Loop Itself

Jan 27, 2015

I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.

int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;

now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.

View Replies View Related

While Loop Inside A For Loop To Determine Proper Length Of Variable

Feb 25, 2014

Here's the code: it's while loop inside a for loop to determine the proper length of a variable:

for (int i = 0; i < num; i++) {
horse[i]=new thoroughbred();
boolean propernamelength = false;
while (propernamelength==false){
String name = entry.getUserInput("Enter the name of horse "

[code]....

I was just wondering what was going on here -- I've initialized the variable, so why do I get this message? (actually the carat was under the variable name inside the parentheses.

View Replies View Related

When Type Quit To Close Outer Loop / It Still Runs Inner Loop

Nov 2, 2014

I have everything else working. My problem is that when i type "quit" to close the outer loop. It still runs the inner loop. The National Bank manager wants you to code a program that reads each clients charges to their Credit Card account and outputs the average charge per client and the overall average for the total number of clients in the Bank.

Hint: The OUTER LOOP in your program should allow the user the name of the client and end the program when the name entered is QUIT.In addition to the outer loop, you need AN INNER LOOP that will allow the user to input the clients charge to his/her account by entering one charge at a time and end inputting the charges whenever she/he enters -1 for a value. This INNER LOOP will performed the Add for all the charges entered for a client and count the number of charges entered.

After INNER LOOP ends, the program calculates an average for this student. The average is calculated by dividing the Total into the number of charges entered. The program prints the average charge for that client, adds the Total to a GrandTotal, assigns zero to the Total and counter variables before it loops back to get the grade for another client.Use DecimalFormat or NumberFormat to format the numeric output to dollar amounts.

The output of the program should something like this:

John Smith average $850.00
Maria Gonzalez average $90.67
Terry Lucas average $959.00
Mickey Mouse course average $6,050.89
National Bank client average $1,987.67

Code:

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String name = "";
int charge = 0;
int count = -1;
int total = 1;
int grandtotal = 0;
int average = 0;
 
[code]....

View Replies View Related

Convert From While Loop To For Loop

Mar 8, 2014

How to convert this program from a while loop to a for loop.

import java.util.Scanner;
public class LongDivision {
public static void main(String arguments[]){
Scanner input = new Scanner(System.in);
System.out.println("Enter the dividend: ");

[Code] ....

View Replies View Related

Converting For Loop To While And Do While Loop

Feb 17, 2014

How do I convert my for loop below to a while and do while loop?

for(int a=1;a<=9;a++){
for(int b=1;b<=a;b++){
System.out.print(a);
}
System.out.println();

[Code] .....

View Replies View Related

How To Store Value From Loop To Add To New Value From Loop

Feb 9, 2015

I am trying to make a program add values from a loop. So what its supposed to do is search through tokens on an imported file. The file lists State, Capital, and then capital population. Then take the population string, turn it into numbers, and then do stuff with the numbers. First I'm supposed to find the Highest and lowest population of the places in the file (which I did without problem), but the finally thing is I'm supposed to add each found population to the last so I can find the average of the populations.

I just cannot seem to grasp how to do that. I THINK I'm supposed to some how store the given value into a variable, but how do I get that variable to add to the new value?

like...?
Get token -> a
b = a
c = a + b

or wait no.....

Java Code :

import java.io.*;
import java.util.Scanner;
public class CapPopS
{
public static void main(String[] args) throws IOException
{
File stateCAP = new File("state-capital-2004population.txt");
if (!stateCAP.exists())

[Code] ....

View Replies View Related

How To Add Within Loop

Feb 9, 2015

My teacher wants me to make a program that counts the amount of steps a student takes a day. The program asks for other info such as name, age, college. However I need to write a loop that will allow the user to enter how many ever steps they took and convert them to miles.how exactly to make the steps entered by the user within the loop be their own individual days like monday tuesday etc. Like the loop will ask how many steps did you take monday.. tuesday.. etc for each time it runs.

package StudentInfo;
import java.util.Scanner;
public class studentinfo {
public static void main (String [] args){
Scanner scan = new Scanner(System.in);

[code]....

View Replies View Related

How To Use While Loop

Apr 5, 2014

I need to write a program that measures how long it will take someone to make a million dollars if he is being paid $5.75 an hour, but the pay rate is increase by 0.2% each week after the third week.

View Replies View Related

Why Won't FOR Loop End

Feb 18, 2014

This is the first time I've ever gotten an infinite loop with a FOR loop. This program is supposed to let you enter five integer numbers and draw a bar chart based on those numbers. After the fifth number is entered, guess what? It wraps back around to zero again and starts over! Why the bleep doesn't it stop? The code is below:

Java Code: import java.awt.Graphics;
import javax.swing.JPanel;
import java.util.Scanner;

[Code]...

View Replies View Related

Inner If Loop Code

Mar 23, 2015

Can i write inner if loop without { and } if it has more lines of code as below

public class TEst111 {
/**
* @param args
*/
public static void main(String[] args) {
int num=11;
// TODO Auto-generated method stub
if (num < 10)

[code]....

I tested to see outer if which does not need { and } even though it has multiple lines in that

View Replies View Related

Conversion From While To For Loop

Aug 3, 2014

I just started to teach myself loops. I am trying to convert the while loop into for loops, however somehow I do not get the same printout.

While loop:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int i = 1;
int sum = 0;

[Code] ....

Print:
sum is 0 and i is 1
sum is 1 and i is 2
sum is 3 and i is 3
sum is 6 and i is 4

View Replies View Related

Loop To Add Integers From 1 To 50?

Mar 11, 2014

Create a loop where you add the integers from 1 to 50.

public class Sum50 {
public static void main(String[] args) {
int sum = 0;
int max = 50;
for(int i = 0;i <= max; i++){
sum=sum+i;
}
System.out.println("Sum is " + sum);
}
}

View Replies View Related

Semicolon After For Loop Is Not Necessary

Jun 15, 2014

I'm fairly new to programming, just started yesterday with a book I downloaded of the net. The book comes with a couple of examples on how to code and they all seem to work fine except for this loop.

class fordemo {
public static void main(String args[] ) {
int count;
for(count = 0; count < 5; count = count+1);
System.out.println(" This is count: " + count);
System.out.println("Your are all done! ");
}
}

I can't seem to find the problem. All it gives me is,
"This is count: 5
You are all done!"

When it's supposed to give me,

"This is count: 1
This is count: 2
This is count: 3
This is count: 4
You are all done!"

Found the error, semicolon after the for loop is not necessary. Should be...

class fordemo {
public static void main(String args[] ) {
int count;
for(count = 0; count < 5; count = count+1)
System.out.println(" This is count: " + count);
System.out.println("Your are all done! ");
}
}

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved