I'm trying to write opus audio packets from a stream to a file using Java so that the file can be successfuly played (via VLC or what have you). I'm currently using the VorbisJava library to no available. Currently, I buffer all the received audio packets and then write the file once I know I am not going to receive any more audio. Here is my sample code so far:
public static void writeWithLibrary(List<OpusAudioData> opusAudioData, OutputStream outputStream)
{
OpusInfo opusInfo = new OpusInfo();
opusInfo.setNumChannels(1);
opusInfo.setOutputGain(0);
opusInfo.setPreSkip(0);
opusInfo.setSampleRate(48000);
OpusTags opusTags = new OpusTags();
OpusFile opusFile = new OpusFile(outputStream,opusInfo,opusTags);
for (OpusAudioData o : opusAudioData)
{
opusFile.writeAudioData(o);
}
try
{
opusFile.close();
}
catch (IOException e)
{
logger.error("OpusFileWriter -- Could not write data to OpusFile, aborting");
}
}
Any help would be appreciated. Am I overlooking something here?