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
ADVERTISEMENT
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
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
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
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
Aug 16, 2014
I have created a playlist class that ask the user to enter a song name and etc. What I want to do is have the mp3 class plays the song that the user has entered, but I don't know how.
Here are my codes:
import java.util.Scanner;
public class PlaylistDriver
{//Start of class
public static Playlist list;
public static void main(String[] args)
{//Start of main
list = new Playlist();
[code]....
View Replies
View Related
Jul 10, 2015
I have a requirement to clip the Text inside a rectangle I am using Canvas API. Below is the sample code. But some how the text is not getting clipped. In SWing we just need to call the setClip method on Graphics2d object. Do we have anything similar in javafx.
public class JavafxClip extends Application{
@Override
public void start(Stage stage) throws Exception {
Group root = new Group();
Canvas canvas = new Canvas(500,500);
[Code] .....
View Replies
View Related
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
View Related
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
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
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
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
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
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
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
Jan 23, 2014
I was looking at the Sound API pages in the java tutorials. I was planning to use it to run wma files. Fortunately, for me, I found, soon into the tutorials, that these API DON'T support the type I have all of my files in (I have a ton of wma files but none of the libraries mentioned support them.)
I almost thought I heard JavaFx or whatever it's called does, but that sounds foreign and Netbeans lists it as a separate type of java in a way, so I don't know if it would be cross-platform or if it could work with the JavaSE API.) Nor do I know what JavaSX or whatever it's called is really, other than that it's more for internet than application.
If I wanted a JPanel or Applet acting as the content pane of a JFrame or being in a JFrame, could I use JavaFX (or whatever it's called) or some third party library (that I always tend to end up spending hours on trying to get it to find the jar files when I import them, so I hope I don't need too many jar files!!!! ) would it work with the JavaSE API?
I don't know much about Java and playing sounds (other than that there is a static method, I think under Toolkit, that will play a system beep) with programs.
However, I can see that that packages don't support certain types (so much for cross-platform!!!!!!! ) and also that a while back that Oracle took over and that they aren't really updating the Java Sound APIs really that much at all
So, without having to learn a whole new Java set of standards (assuming JavaFX or whatever it's called is a different set of standards from JavaSE), is there a way to play .wma?
That's all I seem to have on my computer.
(I suppose I could create new sounds, though if Oracle isn't updating the library, who knows if even that works anymore, but if you're trying to run a Java Media Player that runs lots of DIFFERENT sound file types, this seems a real setback. )
I heard you could convert them to MP3s (I heard there were free things that did it, but who knows if the things aren't filled with viruses that'll do it or, even if they're not, that they'll really mess up the quality of the sound and that I might lose the old .wma file in the process even if it doesn't corrupt the sound.)
But, even if I get a .mp3, I heard the main JavaSE libraries DON'T cover that either, though it was said it was easier to make it run them than .wma files.
MediaPlayer and the main JavaSE classes don't seem to be able to fit for this type of program (a java media player) that I was planning. Heck, they can't even play any music I have on my computer at all, media player or not.
View Replies
View Related
Jun 17, 2014
I am a begMy task is to write a program that plays the "Hi Lo guessing game." The program runs smoothly. However, it does not proceed to the next game after the previous game is done. I need to add a "play again" choice to the program so that the user will continue to play until they have chosen to quit. I have tried several different ways but each one has failed. I am completely stuck on this. I have attached my code to this.
View Replies
View Related
Jun 18, 2014
So, after my graphics card melted down, I decided to use a chat program because I can't play the game server which I am staff on. I've downloaded this:
CactusChat: MC 1.7.4 - 1.7.5 chat client for Windows, Mac and Linux Operating Systems | EcoCityCraft Economy | Minecraft Servers
After I knew it was a .jar file, it would basically fail, I would launch it, it turns into a cmd for 0.5 seconds, and closes without any progress. Typical, and expected.I downloaded the latest java update, removed 3 older versions, and now my Java SE Binary program went missing. I can't even launch it, and it tells me to look for another program to launch it with.
View Replies
View Related
Dec 26, 2014
I wanted to build an mp3 player as a Java project. One crucial part of the project involves being able to play an mp3 fie. I am not able to find the right api (if one exists) and am not able to find a suitable answer when searching on the web. A simple code snippet illustrating the playing of mp3 file using Java program. Also, I am using Eclipse IDE and how to import files if any importing of files is required.
View Replies
View Related
May 13, 2014
I am making a project that should play, stop, and loop three different songs (not at the same time). I am calling this SoundPlayer class from my main class:
import javax.sound.sampled.*;
import java.util.*;
public class SoundPlayer {
List<AudioInputStream> songs = new ArrayList<AudioInputStream>();
int currentSong, currentPlayType;
[Code] ....
When my class calls setPlayType(2), which should make it play, I get the following runtime error:
java.lang.NullPointerException
at SoundPlayer.playSong(SoundPlayer.java:32)
at SoundPlayer.setPlayType(SoundPlayer.java:64)
at MainPanel$AListener.actionPerformed(MainPanel.java:60)
(...)
Line 32 is if(clip.isOpen()), but I'm pretty sure I instantiated clip properly in the constructor.
View Replies
View Related
Apr 17, 2015
I used the following but there's an IOexception. How can I set it up so that it can play audio even after the jar is built?
public void play(){
InputStream in = null;
try {
in = new FileInputStream(new File(filename));
AudioStream audioStream = new AudioStream(in);
AudioPlayer.player.start(audioStream);
in.close();
[Code]...
View Replies
View Related
Feb 10, 2015
How to insert and play a video or a music background in a java application. Let me explain better... I need to develop a game where sometime I need to show picture, or play videos and also, if is possible, add a music in background... I work with eclipse and I know quite good the main concept of java's language...
View Replies
View Related
Jun 26, 2014
how to play audio in a stand alone application.
View Replies
View Related
Nov 6, 2014
Question 1: Upon importing the Play Framework content in Eclipse there's a default codes as localhost:9000 is immediately routed to play framework website controllers, checked and running fine test, checked and running fine conf, checked and running fine the problem is the views under app on all youtube tutorials and other websites, the contents of views is editable but when my brother tried to, he cant edit it
Question 2: Is there an easy tutorial on POST, PUT, GET, and DELETE for eclipse-playframework
Question 3:my brother is using POSTMAN - RESTCLIENT to test his HTTP METHODS (post, put, get, and delete)and is there a tutorial where they also test the HTTP METHODS using POSTMAN?
View Replies
View Related
Feb 25, 2014
I am new to Java, I am using Netbeans to create a simple GUI with one button that just says "play". I want this to play an mp3 file i specify. I have found code to simply play a WAV which works great.There is lots of information on the net about playing an mp3 but it's all long an complicated. There must be a simple way to just have java play an mp3 file.
View Replies
View Related
Dec 15, 2014
I am making a little game for my friend based on HTML and javascript and i was wondering how to play an audio file that i downloaded on to my computer without the user interacting. like a buzzer you would hear on jeopordy or something like that, creating a Wrong answer buzzer and a right answer buzzer into an if/else statement.
View Replies
View Related