嗨,我遇到了很多麻烦,我有 2 个文件,都是 Mp4 格式,将它们读入 FileInputStreams,然后读入 ByteArrayOutputStreams。然后我尝试通过使用另一个 ByteArrayOutputStream [finalOutputStream] 和 write()'ing 来附加两个字节数组。最后,我使用 FileOutputStream 写入(finalOutputStream.toByteArray())、刷新、关闭。当我在手机上查找视频时,有一个“最终”视频应该包含 2 个组合视频,其大小看起来就像两个部分的大小加在一起。但是当我观看视频时,它只是第二部分-_- ...就像第二部分覆盖了第一部分,但是大小增加了?...这里有一些代码..
File fileOne = new File(fileLongName);
File fileTwo = new File(mediaStorageDir.getPath() + File.separator +"VID_TUTPART_"+ (foo-1) + ".mp4");
FileInputStream fisOne = new FileInputStream(fileOne);
FileInputStream fisTwo = new FileInputStream(fileTwo);
int bufferSize = 1024;
//FileOne
byte[] buffer = new byte[bufferSize];
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
//FileTwo
byte[] bufferTwo = new byte[bufferSize];
ByteArrayOutputStream byteBufferTwo = new ByteArrayOutputStream();
int len = 0;
//FileOne to bytebuffer
while ((len = fisOne.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
//FileTwo to bytebuffer
while ((len = fisTwo.read(bufferTwo)) != -1) {
byteBufferTwo.write(buffer, 0, len);
}
byte[] byteArrayOne = byteBuffer.toByteArray();
byte[] byteArrayTwo = byteBuffer.toByteArray();
ByteArrayOutputStream finalOutputStream = new ByteArrayOutputStream( );
finalOutputStream.write( byteArrayOne );
finalOutputStream.write( byteArrayTwo );
int counterFileNumber = 0;
while(new File(mediaStorageDir.getPath() + File.separator +"VID_TO_TUTFIN_"+ counterFileNumber + ".mp4").exists()){
counterFileNumber++;
}
String outputFileNameString = mediaStorageDir.getPath() + File.separator +"VID_TO_TUTFIN_"+ counterFileNumber + ".mp4";
File outputFile = new File(outputFileNameString);
FileOutputStream fos = new FileOutputStream(outputFile);
fos.write(finalOutputStream.toByteArray());
fos.flush();
fos.close();