• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stanford CS 106 Breakout Assignment, Sound clip using mediatools class will not play  RSS feed

 
Dennis Ouyang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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)

I have no idea what the values it refers to could mean, or 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: http://cs.stanford.edu/people/eroberts/jtf/rationale/UtilPackage.html#MediaTools.

I went ahead and tested all parts of the program and the missing sound effect is the only problem. Here is my complete code:

 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means something is passing −120.0 when you are not allowed anything below −80.0. Look at the line numbers. There is a method or a constructor which has that restriction built in.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a 5‑second look at your code, which is difficult to read because of the long lines and too many // comments where you should be using /* comments */, I didn't see where you were setting that volume.
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting that there is another thread about this here. Is the wav file valid? Can you play it in Windows Media Player?
 
Dennis Ouyang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plays just fine in both windows media player and quicktime. Like others have mentioned, I am definitely not including anything in my code above to set a value for the sound file. Is it possible that this has something to do with my hardware?

Has anyone else tried running the code on their machine to see if they can reproduce?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of Java are you running? The behavior looks like it may be related to this old bug or maybe even this one.
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Ouyang wrote:Has anyone else tried running the code on their machine to see if they can reproduce?


Works fine for me, but I'm using another sound file. Why don't you try using that one (or another). In particular, can the acm package handle au files?

UPDATE: I just tried an au file and it worked fine. I'm using Java 1.8.
 
Dennis Ouyang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that file safe to download? I clicked the download link and ran the installer, it tried to install Astromenda and a bunch of other crap on my machine. I know Astromenda is adware.

Also, I am using java 1.7.0_67-b01, according to about menu in the java control panel.
 
Dennis Ouyang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just tried using another sound file from this link: http://soundbible.com/1120-Bounce.html. (I realize that this is the same link knute directed me to, not sure why I somehow got redirected into downloading adware, of all things. Fortunately I figured out what was happening and stopped installation in time. )

First I tried using it in the default .wav format. Got the exact same error message.

then tried changing the format to .au , restarting eclipse JDK, changing file format to .au in my MediaTools method, refreshing the package and playing again. Exact same error message. Is anyone else getting this on their machine?
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try:

  • Not converting the sound file. Use it as a .wav.
  • Upgrading your Java. 1.7.0 is pretty old.


  • Here's the download page for Java 1.7.
     
    Dennis Ouyang
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So I downloaded java version 8 update 25, latest version for windows 8, from www.java.com. As part of installation I uninstalled my old java 7 update 67, then manually uninstalled it again after it still showed in programs and features. Java website confirms I successfully installed that version 8u25. I deleted every sound file in the project folder and downloaded the same .wav you linked me to above, made no changes to .wav file except rename it to "bounce.wav". I refresh eclipse project and run it, and I get the exact same error message.

    I keep thinking it must have something to do with my new hardware. I tried playing around with my speakers and sound settings in windows, tried having sound come from the "AMD HD audio device" connected to my monitor. Same problem.
     
    Carlos Loza
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have the exact same error message. I was looking for a solutions in google when I found your post... Did you realize what the solution was?
     
    Dennis Ouyang
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    No, sorry. I moved on to other chapters and assignments since I didn't want to spend too much time on this issue. Out of curiosity, do you use Windows 8?
     
    Carlos Loza
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Dennis Ouyang wrote:No, sorry. I moved on to other chapters and assignments since I didn't want to spend too much time on this issue. Out of curiosity, do you use Windows 8?


    Noup, I'm using OS X Yosemite 10.10.1 thanks anyway.
     
    Carlos Cerda
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm also doing the Stanford's CS106 class and had the same error message.  Like Carlos Loza I found this post googling for a solution.  It take me some time but I find a solution.  It's been more than 2 years but maybe this will help others that find this looking for a solution. 

    First, add this import: import java.net.URL;

    Second, add this (I added it at the end of the program):



    Third: Substitute this: AudioClip bounceClip = MediaTools.loadAudioClip("bounce.au");
             With this:         AudioClip bounceClip = Applet.newAudioClip(Get_Location("bounce.au"));


    I hope it works for you or anyone else.
     
    Campbell Ritchie
    Marshal
    Posts: 56599
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Welcome to the Ranch and well done posting a potential solution. But why are they using Applets? Nobody else uses applets any more.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!