use of com.bixly.pastevid.models.AudioFileItem in project screenbird by adamhub.
the class AudioRecorder method compileAudio.
/**
*
* @param audioFileName
*/
public void compileAudio(String audioFileName) {
if (this.getAudioFiles().size() > 0) {
try {
AudioFormat format = null;
int audioFilesSize = this.getAudioFiles().size();
for (int i = 0; i < audioFilesSize; i++) {
if (i < audioFilesSize - 1) {
AudioFileItem audioFileItem = this.getAudioFiles().get(i);
File audioFile = new File(audioFileItem.getName());
if (audioFile.isFile()) {
long audioLength = audioFileItem.getEndMS() - audioFileItem.getStartMS();
AudioRecorder.cutAudioFile(audioFile, audioLength);
}
}
}
File file = new File(audioFileName);
this.audioInputStreams = new Vector<AudioInputStream>();
long length = 0;
long correctStartTimestamp = 0;
// Iterate over audio files
for (int i = 0; i < audioFilesSize; i++) {
AudioFileItem audioFileItem = this.getAudioFiles().get(i);
File audioFile = new File(audioFileItem.getName());
if (audioFile.isFile()) {
AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
// Checks if we need to add empty sound before adding the sound file
if (audioFileItem.getStartMS() > correctStartTimestamp && audioFileItem.isPreviousDropped()) {
// The correct start time for the audio file should
// be 0 if it's the first file or equals the end
// time of the prev audio file
AudioInputStream audioStreamEmpty = addEmptySound(audioFileItem.getStartMS(), correctStartTimestamp);
length += audioStreamEmpty.getFrameLength();
this.audioInputStreams.add(audioStreamEmpty);
}
correctStartTimestamp = audioFileItem.getStartMS() + (long) (1000 * audioStream.getFrameLength() / audioStream.getFormat().getFrameRate());
format = audioStream.getFormat();
length += audioStream.getFrameLength();
this.audioInputStreams.add(audioStream);
}
}
compileAudioStreams(this.audioInputStreams, file, format, length);
} catch (IOException ex) {
log(ex);
} catch (UnsupportedAudioFileException e) {
log(e);
}
}
}
use of com.bixly.pastevid.models.AudioFileItem in project screenbird by adamhub.
the class Recorder method restoreVideoState.
/**
* Restores previous recording based on saved video and audio data.
*/
public void restoreVideoState() {
VideoFileItem videoFileItem;
ArrayList<AudioFileItem> audioFileItems;
this.createGeneralDirectory();
if (FileUtil.previousVideoExists(Recorder.VIDEO_DATA)) {
videoFileItem = (VideoFileItem) FileUtil.readObjectDataFromFile(Recorder.VIDEO_DATA);
videoRecorder.restoreVideoFileItem(videoFileItem);
// Restore audio only if it has accompanying video
if (FileUtil.previousVideoExists(Recorder.AUDIO_DATA)) {
audioFileItems = (ArrayList) FileUtil.readObjectDataFromFile(Recorder.AUDIO_DATA);
audioRecorder.setAudioFiles(audioFileItems);
}
}
}
use of com.bixly.pastevid.models.AudioFileItem in project screenbird by adamhub.
the class AudioRecorder method generateAudioFileItem.
/**
* Generates an audio file item for the recording.
* @param postfix
* @param dropped
* @param previousDropped
* @return
*/
private AudioFileItem generateAudioFileItem(long postfix, boolean dropped, boolean previousDropped) {
String audioFile = recordingDir + FileUtil.addExtension(String.valueOf(System.currentTimeMillis()), "audio");
AudioFileItem audioFileItem = new AudioFileItem();
audioFileItem.setName(audioFile);
audioFileItem.setDropped(dropped);
audioFileItem.setPreviousDropped(previousDropped);
audioFileItem.setTimestamp(postfix);
this.getAudioFiles().add(audioFileItem);
return audioFileItem;
}
Aggregations