String revision = currentRecordingDoc.get("_rev").getTextValue();
try {
// mp3
FileInputStream fis = new FileInputStream(t.getRecordings()[0]);
AttachmentInputStream ais = new AttachmentInputStream("complete.mp3",fis, "audio/mp3");
revision = connector.createAttachment(id, revision, ais);
ais.close();
fis.close();
} catch(Exception e) {
}
try {
if (t.getRecordings().length == 2){
// ogg
FileInputStream fis = new FileInputStream(t.getRecordings()[1]);
AttachmentInputStream ais = new AttachmentInputStream("complete.ogg",fis, "audio/ogg");
revision = connector.createAttachment(id, revision, ais);
ais.close();
fis.close();
}
} catch (Exception e) {
}
EventBus.publish(new UploadingFinishedEvent());
// lame extra get
currentRecordingDoc = loadRecordingDoc(id);
ObjectNode recordingState = getRecordingState(currentRecordingDoc);
recordingState.put("recordingComplete", new Date().getTime());
connector.update(currentRecordingDoc);
currentRecordingDoc = null;
}
});
EventBus.subscribeStrongly(StreamReadyEvent.class, new EventSubscriber<StreamReadyEvent>() {
@Override
public void onEvent(StreamReadyEvent t) {
System.out.println("Streaming");
if (streamAudio) {
try {
System.out.println("out");
// create a doc
ObjectMapper map = new ObjectMapper();
ObjectNode node = map.createObjectNode();
node.put("type", "com.eckoit.recordingSegment");
node.put("recording", currentRecordingDoc.get("_id").getTextValue());
node.put("startTime", t.getStartTime());
connector.create(node);
String id = node.get("_id").getTextValue();
String rev = node.get("_rev").getTextValue();
{
// attach stream
FileInputStream fis = new FileInputStream(t.getAvailableToStream());
String name = "fileSequence" + t.getSegmentCount() + ".ts";
AttachmentInputStream ais = new AttachmentInputStream(name,fis, t.getContentType());
rev = connector.createAttachment(id, rev, ais);
ais.close();
fis.close();
}
{
// attach mp3
FileInputStream fis = new FileInputStream(t.getFinishedFile());
String name = "fileSequence" + t.getSegmentCount() + ".mp3";
AttachmentInputStream ais = new AttachmentInputStream(name,fis, "audio/mp3");
rev = connector.createAttachment(id, rev, ais);
ais.close();
fis.close();
}
} catch (Exception e) {