I want to record a mp4 file from bitmap arraylist.
My code:
File directory = intiFilePath();
DataOutputStream out = new DataOutputStream(new FileOutputStream(directory.getPath()+"/test.mp4"));
int maxBufferSize = 256 * 1024;// 256KB
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
for (Bitmap n : bmpList) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
n.compress(Bitmap.CompressFormat.JPEG, 100, bos);
byte[] bitmapdata = bos.toByteArray();
ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
DataInputStream in = new DataInputStream(bs);
bytesAvailable = in.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
bytesRead = in.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
out.write(buffer, 0, bytesRead);
out.flush();
bytesAvailable = in.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = in.read(buffer, 0, bufferSize);
}
in.close();
}
out.close();
But the mp4 file cannot play (the file is exist).
Anyone can help me what's wrong.