I`m trying to put some music or a short clip of a sound to my project. I try some helps from here. It kinda work, but I could not hear anything. It just wrote that its playing.
I found a lot of examples, but nothing is working for me. Maybe you can help me with that AudioStream, AudioPlayer. Many people are using it. How can I use it in my Java Eclipse 4.4.0?
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JFrame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import sun.audio.*;
public class zaciatky {
public static void main(String[] args) throws LineUnavailableException {
// TODO Auto-generated method stub
try {
AudioInputStream audoAudioInputStream=AudioSystem.getAudioInputStream(new File("D:\\Betka\\Dokumenty\\INF\\JAVA\\Saxik\\Music\\saxik.wav"));
Clip songik=AudioSystem.getClip();
songik.open(audoAudioInputStream);
songik.start();
System.out.println("Song is playing...");
System.out.println(songik.getFormat());
if(songik.isActive()) System.out.println("is active");
songik.stop();
if(songik.isActive()) System.out.println("is active");
else System.out.println("not active");
} catch (UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
System.out.println("Error occures with playing the sound.");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Error occures with playing the sound.");
e.printStackTrace();
}
}
}