PDA

View Full Version : سوال: يك پلير ساده



ravand
جمعه 19 خرداد 1391, 20:56 عصر
خواستم تا كدي بنويسم كه يك فايل صوتي رو بخونه ولي كار نكرد:
package po;

import java.io.*;
import sun.audio.*;


public class TestDB
{
public static void main(String[] args)
throws Exception
{

String soundFile = "ahan.wma";
InputStream in = new FileInputStream(soundFile);


AudioStream audioStream = new AudioStream(in);


AudioPlayer.player.start(audioStream);
}
}

mortezaadi
شنبه 20 خرداد 1391, 23:09 عصر
این تابع فقط فایل .wave رو اجرا میکنه

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;

public static synchronized void playSound(final String url) {
new Thread(new Runnable() {
public void run() {
try {
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(Main.class.getReso urceAsStream("/path/to/sounds/" + url));
clip.open(inputStream);
clip.start();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}).start();
}