即時發送視頻,互聯網服務和工程確定與小於10MB的視頻,如果視頻是大約12MB給我的OutOfMemoryError:的OutOfMemoryError ByteArrayOutputStream發送大文件,WS
這是我的代碼:
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
}
我認爲這是因爲我緩衝所有的視頻,但我不知道如何發送這個緩衝區沒有saviing。
這是堆棧錯誤:
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(緩衝液,0,緩衝區大小);
有什麼辦法可以發送視頻?謝謝
你能給我一個例子使用ioutils嗎?我不知道我該怎麼做。謝謝 – rbrlnx
我用ioutils的例子更新了我的答案。 –
這將我複製到dos 0字節:S – rbrlnx