我将视频发送到网络服务,并且可以处理小于 10MB 的视频,如果视频大约 12MB,给我内存不足错误:
这是我的代码:
FileInputStream fileInputStream = new FileInputStream(fichero);
int bytesAvailable = fileInputStream.available();
int maxBufferSize = 1024 * 1024 * 2;
int bufferSize = Math.min(bytesAvailable, maxBufferSize);
byte[] buffer = new byte[bufferSize];
int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
// nuevos
byte byt[] = new byte[bufferSize];
fileInputStream.read(byt);
// nuevos
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
// esto es nuevo
dos.write(buffer, 0, bufferSize);
// ya no es nuevo
}
我认为这是因为我正在缓冲所有视频,但我不知道如何在不保存缓冲区的情况下发送它。
这是堆栈错误:
08-31 08:54:20.925: E/AndroidRuntime(18476): Caused by: java.lang.OutOfMemoryError
08-31 08:54:20.925: E/AndroidRuntime(18476): at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
08-31 08:54:20.925: E/AndroidRuntime(18476): at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:216)
08-31 08:54:20.925: E/AndroidRuntime(18476): at org.apache.harmony.luni.internal.net.www.protocol.http.RetryableOutputStream.write(RetryableOutputStream.java:60)
08-31 08:54:20.925: E/AndroidRuntime(18476): at java.io.DataOutputStream.write(DataOutputStream.java:99)
08-31 08:54:20.925: E/AndroidRuntime(18476): at com.reparalia.movilidad.AdjuntarFicheros$SubeFichero.doInBackground(AdjuntarFicheros.java:702)
08-31 08:54:20.925: E/AndroidRuntime(18476): at com.reparalia.movilidad.AdjuntarFicheros$SubeFichero.doInBackground(AdjuntarFicheros.java:1)
702行是dos.write(buffer, 0, bufferSize);
有什么方法可以发送视频吗?谢谢