Java Reference
In-Depth Information
if (!musicDir.exists()) {
musicDir.mkdirs();
}
return musicDir;
}
private URL createLocalFile(String urlStr) throws Exception {
File musicDir = getMusicDir();
String fileName = urlStr.substring(urlStr.lastIndexOf('/')).replace("%20", " ");
File musicFile = new File(musicDir, fileName);
if (!musicFile.exists()) {
InputStream is = new URL(urlStr).openStream();
FileOutputStream fos = new FileOutputStream(musicFile);
byte[] buffer = new byte[512];
int nBytesRead = 0;
while ((nBytesRead = is.read(buffer, 0, buffer.length)) != -1) {
fos.write(buffer, 0, nBytesRead);
}
fos.close();
}
return musicFile.toURL();
}
private void init() {
fft = new FFT(saFFTSampleSize);
old_FFT = new float[saFFTSampleSize];
saMultiplier = (saFFTSampleSize / 2) / saBands;
AudioInputStream in = null;
try {
in = AudioSystem.getAudioInputStream(url.openStream());
AudioFormat baseFormat = in.getFormat();
decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(), false);
AudioInputStream decodedInputStream =
AudioSystem.getAudioInputStream(decodedFormat, in);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Search WWH ::




Custom Search