-4

Figured it out and answered the question myself
I have this code and I am pretty sure this is supposed to make a sound but it won't. The program shows no errors when it runs but won't produce sound. I need help figuring out why it is not working.

import java.net.*;
import java.applet.*;

  if(true)
  {
     File file= new File("GodzillaWAV.wav");
     AudioClip roar= Applet.newAudioClip(file);
     roar.loop();
  }

Thanks to those that could help.

user3144079
  • 159
  • 3
  • 12

3 Answers3

1

You can't play mp3 files using AudioClip, unfortunately. You can either try out this answer or download the file and convert it to wave sound (.wav).

Community
  • 1
  • 1
TNT
  • 2,900
  • 3
  • 23
  • 34
0

try this:

import java.io.*;
import sun.audio.*;
String MainSound =  "/Users/al/DevDaily/Projects/MeditationApp/resources/gong.au";
InputStream inSound = new FileInputStream(MainSound);
AudioStream audioStream = new AudioStream(inSound );
AudioPlayer.player.start(audioStream);
Eth.
  • 3
  • 5
  • Instead of a url I am using a file and using this code it only plays for a fraction second then cuts out – user3144079 Jan 19 '15 at 23:57
  • Okay so you are using a File now? Okay then it will be easier than before, To play it you from A file you should do that: – Eth. Jan 21 '15 at 22:28
0

This works no clue why or why not but it works.

  if(true)
  {
     File file = new File("GodzillaWAV.wav");
     Clip clip = AudioSystem.getClip();
     AudioInputStream Audio = AudioSystem.getAudioInputStream(file);
     clip.open(Audio);
     clip.loop(Clip.LOOP_CONTINUOUSLY);
     Thread.sleep(6000);
  }
user3144079
  • 159
  • 3
  • 12
  • It's because it's a .wav file, not a .mp3 file like you were trying to play. The JMF contains tools that actually support .mp3 files. You might consider looking into it. – TNT Jan 20 '15 at 02:09