Skip to content

Instantly share code, notes, and snippets.

@scottdavis
Created February 14, 2010 18:34
Show Gist options
  • Save scottdavis/304170 to your computer and use it in GitHub Desktop.
Save scottdavis/304170 to your computer and use it in GitHub Desktop.
/**
* Sets the audio file from which the data-stream will be generated of.
*
* @param audioFileURL The location of the audio file to use
* @param streamName The name of the InputStream. if <code>null</code> the complete path of the audio file will be
* uses as stream name.
*/
public void setAudioFile(URL audioFileURL, String streamName) {
// first close the last stream if there's such a one
if (dataStream != null) {
try {
dataStream.close();
} catch (IOException e) {
e.printStackTrace();
}
dataStream = null;
}
assert audioFileURL != null;
if (streamName != null)
streamName = audioFileURL.getPath();
AudioInputStream audioStream = null;
try {
audioStream = AudioSystem.getAudioInputStream(audioFileURL);
} catch (UnsupportedAudioFileException e) {
System.err.println("Audio file format not supported: " + e);
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
curAudioFile = new File(audioFileURL.getFile());
for (AudioFileProcessListener fileListener : fileListeners)
fileListener.audioFileProcStarted(curAudioFile);
setInputStream(audioStream, streamName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment