アットウィキロゴ

わx

package sound;
 
 import javax.sound.sampled.*;
 import java.io.*;
 
public class pro {
 
 
    public static void main(String[] args) {
        pro t=new pro();
    }
 
    pro(){
 
 
        playw("s.wav");
 
    }
 
 
    public void playw(String fileName){
     try{
 
         File file=new File(fileName);
        if(file.exists()){
            AudioInputStream stream=AudioSystem.getAudioInputStream(file);
            byte[] buf=new byte[stream.available()];
            stream.read(buf,0,buf.length);
 
            AudioFormat format=stream.getFormat();
            long nBytesRead=format.getFrameSize()*stream.getFrameLength();
 
            DataLine.Info info=new DataLine.Info(SourceDataLine.class,format);
            SourceDataLine line=(SourceDataLine)AudioSystem.getLine(info);
 
 
            line.open(format);
            line.start();
 
 
            line.write(buf,0,(int)nBytesRead);
 
 
            line.drain();
            line.close();
         }
      }catch(Exception e){e.printStackTrace();}
    }  
}
 
最終更新:2015年04月11日 23:59