Commit 934f60af authored by thurner's avatar thurner

parent 79f4fddc
......@@ -144,7 +144,7 @@ public class HextileMessage extends FramebufferUpdateMessage {
}
static private void hextileRectToJson(GraphicsContext graphicsContext, BufferedWriter out, DataInputStream is, int x, int y, int w, int h, boolean updateFlag) throws IOException {
byte[] read = new byte[16];
byte[] read = new byte[3];
int isEof = is.read(read);
while(isEof != -1) {
out.write(Base64Coder.encode(read));
......
......@@ -422,7 +422,7 @@ public class PostProcessorPanel extends GradientPanel {
mp4StatusField.setText("not found");
}
//html5
if (new File(recording.getDirectory() + Html5Context.HTML5_DIRECTORY).isDirectory()) {
if (new File(Html5Context.getWebPlayerDirectory(recording)).isDirectory()) {
html5StatusField.setForeground(Color.GREEN);
html5StatusField.setText("folder found");
html5StatusField.setToolTipText("folder exists - content not confirmed");
......@@ -1526,7 +1526,7 @@ public class PostProcessorPanel extends GradientPanel {
// create html5 player files
try {
if (html5PlayerCheckBox.isSelected()) {
Html5PlayerCreator.createPlayer(new File(recording.getDirectory() + Html5Context.HTML5_DIRECTORY));
Html5PlayerCreator.createPlayer(new File(Html5Context.getWebPlayerDirectory(recording)));
}
} catch (Exception e) {
TTT.showMessage("HTML5 player creation failed: " + e);
......
package ttt.postprocessing.html5;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;
public class CountingBufferedWriter extends BufferedWriter {
private long bytesWritten = 0;
public CountingBufferedWriter(Writer out) {
super(out);
}
public CountingBufferedWriter(Writer out, int sz) {
super(out, sz);
}
public void write(int c) throws IOException {
super.write(c);
this.increaseBytesWritten(1);
}
public void write(char cbuf[], int off, int len) throws IOException {
super.write(cbuf, off, len);
this.increaseBytesWritten(len-off);
}
public void write(String s, int off, int len) throws IOException {
super.write(s, off, len);
this.increaseBytesWritten(s.substring(off, off+len).getBytes().length);
}
private void increaseBytesWritten(long inc) {
this.bytesWritten += inc;
}
public long getBytesWritten() {
return this.bytesWritten;
}
}
......@@ -28,7 +28,6 @@ import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
......@@ -51,11 +50,12 @@ public class Html5Context {
public static boolean html5_debug = false;
public static final String thumbnailImageFormat = "png";
public static final String HTML5_DIRECTORY = "webplayer";
public static final String FILE_NAME = "lecture";
public static final long MAX_FILE_SIZE = 5*1024*1024; //5 MB
private static final String HTML5_DIR_SUFFIX = "_webplayer";
private boolean batch;
public Recording recording;
public BufferedWriter out;
public CountingBufferedWriter out;
static public void createJson(Recording recording, boolean batch) throws IOException {
Html5Context html5Context = new Html5Context(recording, batch);
......@@ -71,6 +71,10 @@ public class Html5Context {
this.recording = recording;
this.batch = batch;
}
static public String getWebPlayerDirectory(Recording recording) throws IOException {
return recording.getDirectory() + recording.getFileBase() + HTML5_DIR_SUFFIX;
}
// use to save the corresponding timestamp in the first frame of each clip
ArrayList<Integer> bufferTimestampClip = new ArrayList<Integer>();
......@@ -110,11 +114,6 @@ public class Html5Context {
progressMonitor.setNote("converting thumbnails");
}
// determine width and height of thumbnails
IndexEntry entry = recording.index.get(0);
ImageIcon imIcon = entry.getThumbnail();
Image im = imIcon.getImage();
// buffer index information
for (int i = 0; i < recording.index.size(); i++) {
IndexEntry ie = recording.index.get(i);
......@@ -133,16 +132,16 @@ public class Html5Context {
private void createJson() throws IOException {
try {
File html5dir = new File(recording.getDirectory() + HTML5_DIRECTORY);
File html5dir = new File(getWebPlayerDirectory(this.recording));
if (!html5dir.isDirectory()) {
//create dir
html5dir.mkdir();
}
//write file
String fileName = recording.getDirectory() + HTML5_DIRECTORY + "/" + FILE_NAME + ".js";
String fileName = getWebPlayerDirectory(this.recording) + "/" + FILE_NAME + ".js";
FileWriter fstream = new FileWriter(fileName);
this.out = new BufferedWriter(fstream);
this.out = new CountingBufferedWriter(fstream);
if (!batch) {
// show progress
......@@ -158,11 +157,13 @@ public class Html5Context {
this.initialize();
//JSON with padding
String paddingEnd = "})});";
out.write("$(function(){controller.loadData({");
//PREFS
out.write("\"prefs\":"+this.recording.graphicsContext.prefs.toJson()+",");
//THUMBNAILS
if (!batch) {
if (progressMonitor == null || progressMonitor.isCanceled()) {
......@@ -183,6 +184,8 @@ public class Html5Context {
progressMonitor.setNote("converting messages");
}
int fileCounter = 2;
out.write(", \"messages\": [");
for (int i = 0; i < recording.messages.size(); i++) {
if (!batch) {
......@@ -191,18 +194,34 @@ public class Html5Context {
}
progressMonitor.setProgress(10 + (60 * i / recording.messages.size()));
}
message = recording.messages.get(i);
message.writeToJson(this);
if (i < recording.messages.size()-1) {
out.flush();
//split into multiple js files if too big
if (out.getBytesWritten() >= MAX_FILE_SIZE) {
String newFileName = FILE_NAME+fileCounter+".js";
//write custom message so the player knows that it should load a new file
out.write(",{\"type\":\"NewFileIndicator\",\"id\":"+fileCounter+",\"fileName\":\""+newFileName+"\"}]"+paddingEnd);
out.flush();
out.close();
fstream = new FileWriter(getWebPlayerDirectory(this.recording) + "/" + newFileName);
this.out = new CountingBufferedWriter(fstream);
out.write("$(function(){controller.loadAdditionalData({\"id\":"+fileCounter+",\"messages\": [");
fileCounter++;
} else if (i < recording.messages.size()-1) {
out.write(",");
}
}
out.write("]");
//close padding
out.write("})});");
out.write(paddingEnd);
if (!batch) {
......@@ -237,7 +256,7 @@ public class Html5Context {
//copy audio to html5 directory, if existent
String[] audioFormatSuffix = {"mp3", "ogg"};
for (int i = 0; i < audioFormatSuffix.length; i++) {
File target = new File(recording.getDirectory() + HTML5_DIRECTORY + "/" + FILE_NAME + "." + audioFormatSuffix[i]);
File target = new File(getWebPlayerDirectory(this.recording) + "/" + FILE_NAME + "." + audioFormatSuffix[i]);
if (recording.getExistingFileBySuffix(audioFormatSuffix[i]).exists() && !target.exists()) {
Html5PlayerCreator.copyFile(recording.getExistingFileBySuffix(audioFormatSuffix[i]), target);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment