video tag reads the file stream written by java (MP4 video encoding is h264). The page code is as follows:
<video width="320" height="240" controls="controls">
<source src="http://192.168.254.107:8080/testvideo!test.do" type="video/mp4" />
video
</video>
the java code is as follows:
public void test() {
try {
File f = new File("F:/MyWorkSpace/wrote/c/cath264.mp4");
if (!f.exists()) {
response.sendError(404, "File not found!");
return;
}
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
byte[] buf = new byte[1024];
int len = 0;
response.reset();
response.setContentType("video/mp4");
response.setHeader("Accept-Ranges", "0-" + f.length());
response.setHeader("Content-Range",
"bytes " + 0 + "-" + (f.length() - 1) + "/" + f.length());
response.setHeader("Content-Length", f.length() + "");
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
videos can be played on both PC and Android browsers, but not on Safari in iPhone
PCSafari:
videoSafari