我需要将视频发送到 .net 中的 web 服务,我发送一个字符串 base64 编码,如果视频大约 2MB 或 6 o 7 秒一切正常,但当我执行 Bas.encode 时更重会导致内存不足错误[字节[]);
这是我的代码:
videoPath = getRealPathFromURI(fileUri);
File tmpFile = new File(videoPath);
in = null;
in = new BufferedInputStream(new FileInputStream(tmpFile));
bos = new ByteArrayOutputStream();
long tamano = tmpFile.length();
int iTamano = (int) tamano;
byte[] b = new byte[iTamano];
int bytesRead;
while ((bytesRead = in.read(b)) != -1) {
bos.write(b, 0, bytesRead);
}
ficheroAEnviar = bos.toByteArray();
try {
strBase64 = Base64.encode(ficheroAEnviar);
}
catch (Exception e) {
correcto = false;
e.printStackTrace();
}
此行崩溃:strBase64 = Base64.encode(ficheroAEnviar);
最佳答案
你不能这样做。内存是android中的一个问题。您应该将视频分成几部分,对每个部分进行编码,发送(我想您想通过 WS 或其他方式发送)并在目的地重新组合。
关于android - 大视频到字符串 base64 导致内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11775036/