06-21 12:35:37.275: E/AndroidRuntime(12402): FATAL EXCEPTION: Thread-1864
06-21 12:35:37.275: E/AndroidRuntime(12402): java.lang.OutOfMemoryError
06-21 12:35:37.275: E/AndroidRuntime(12402): at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
06-21 12:35:37.275: E/AndroidRuntime(12402): at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
06-21 12:35:37.275: E/AndroidRuntime(12402): at libcore.net.http.RetryableOutputStream.write(RetryableOutputStream.java:61)
06-21 12:35:37.275: E/AndroidRuntime(12402): at java.io.BufferedOutputStream.write(BufferedOutputStream.java:131)
06-21 12:35:37.275: E/AndroidRuntime(12402): at java.io.OutputStream.write(OutputStream.java:82)
06-21 12:35:37.275: E/AndroidRuntime(12402): at com.facebook.android.Util.openUrl(Util.java:190)
06-21 12:35:37.275: E/AndroidRuntime(12402): at com.facebook.android.Facebook.request(Facebook.java:563)
06-21 12:35:37.275: E/AndroidRuntime(12402): at dev.env.secvideo.SaveActivity$FBRequestListener.onComplete(SaveActivity.java:467)
06-21 12:35:37.275: E/AndroidRuntime(12402): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:254)
当我尝试从我的应用程序将视频上传到 Facebook 时。我收到此错误消息。我的视频大小约为 15-20 MB。我的代码在较低版本中正常运行。我仅在 4.0 以上的较高版本中出现此错误
我正在使用以下代码
public byte[] readBytes(String path) throws IOException {
InputStream is = new FileInputStream(path);
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(path.length());
//int bufferSize = 30*1024;
byte[] buffer = new byte[path.length()];
int len = 0;
while ((len = is.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
return byteBuffer.toByteArray();
}
public class FBRequestListener implements RequestListener
{
@Override
public void onComplete(String response, Object state) {
byte[] data = null;
String path = Environment.getExternalStorageDirectory()+"/recordvideooutput.3gp";
String datapath = new File(path).getAbsolutePath();
String datamsg = "My Video";
Bundle params;
try {
//InputStream is = new FileInputStream(datapath);
//data = readBytes(is);
data = readBytes(datapath);
params = new Bundle();
params.putString(Facebook.TOKEN, access_token);
params.putString("message", datamsg);
params.putString("contentType", "video/quicktime");
params.putByteArray("video.mov", data);
String request = facebook.request("me/videos", params, "POST");
Log.i("request", request);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onIOException(IOException e, Object state) {
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
}
@Override
public void onFacebookError(FacebookError e, Object state) {
}
}