Qualche anima pia che mi spiega un po cosa fa questo metodo che non ho scritto io . Help meeeeee!!
commentandomi magari un po i metodi.. lo so c'è la documentazione ... ma ahime non riesco a capire molto..codice:package jCallRemember.libreria; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; import java.io.File; import java.io.IOException; import javax.sound.sampled.UnsupportedAudioFileException; /** * * @author Linux * Classe che si occupa della riproduzione di un file wav */ public class WAVPlayer { private final int BUFFER_SIZE = 128000; private File soundFile; private AudioInputStream audioStream; private AudioFormat audioFormat; private SourceDataLine sourceLine; /** * @param filename the name of the file that is going to be played * @throws javax.sound.sampled.LineUnavailableException * @throws java.io.IOException * @throws javax.sound.sampled.UnsupportedAudioFileException */ public void playSound(String filename) throws LineUnavailableException, IOException, UnsupportedAudioFileException { String strFilename = filename; soundFile = new File(strFilename); audioStream = AudioSystem.getAudioInputStream(soundFile); audioFormat = audioStream.getFormat(); DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat); sourceLine = (SourceDataLine) AudioSystem.getLine(info); sourceLine.open(audioFormat); sourceLine.start(); int nBytesRead = 0; byte[] abData = new byte[BUFFER_SIZE]; while (nBytesRead != -1) { nBytesRead = audioStream.read(abData, 0, abData.length); if (nBytesRead >= 0) { sourceLine.write(abData, 0, nBytesRead); } } sourceLine.drain(); sourceLine.close(); } }

Rispondi quotando