Quality and size
Here are some interesting articles about the differences between MP3 and WAV.
MP3 WAV? , , .
Java , . , , , ..
, : Java?.
, , . javax.swing, , , , .
, , MP3.
import sun.audio.*;
import java.io.*;
public class Sound {
private InputStream input;
private AudioStream audio;
public Sound (File fileName)
{
input = new FileInputStream();
audio = new AudioStream(input);
}
public void play()
{
AudioPlayer.player.start(audio);
}
public void stop()
{
AudioPlayer.player.stop(audio);
}
}
:
String projectPath = <project directory>; // getting this is another question
Sound helloSound = new Sound(new File(projectPath + "/Sounds"));
helloSound.play(); , , .
, , . , . .
,
MP3 , . , .
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import javazoom.jl.player.Player;
public class MP3 {
private String filename;
private Player player;
public MP3(String filename) {
this.filename = filename;
}
public void close() { if (player != null) player.close(); }
public void play() {
try {
FileInputStream fis = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(fis);
player = new Player(bis);
}
catch (Exception e) {
System.out.println("Problem playing file " + filename);
System.out.println(e);
}
new Thread() {
public void run() {
try { player.play(); }
catch (Exception e) { System.out.println(e); }
}
}.start();
}
public static void main(String[] args) {
String filename = args[0];
MP3 mp3 = new MP3(filename);
mp3.play();
int N = 4000;
double sum = 0.0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
sum += Math.sin(i + j);
}
}
System.out.println(sum);
mp3.close();
mp3 = new MP3(filename);
mp3.play();
}
}
, , ?;.)
jar . . .