3
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.AsyncFacebookRunner2ドル.run(AsyncFacebookRunner.java:254)

when i am trying to upload video to facebook from my app.i am getting this error message.my video size is around 15-20 MB. My code is running correctly in lower versions.I am getting this error only in higher version above 4.0

I am using following code

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) {
 }
 }
asked Jun 21, 2013 at 7:14
6
  • How can we help you without source code ? Commented Jun 21, 2013 at 7:15
  • You are loading the entire file into memory. Is there now way to stream the file from disk to the network? Commented Jun 21, 2013 at 7:22
  • What is your facebook object that you are calling facebook.request on? Commented Jun 21, 2013 at 7:24
  • am using facebook.request to share my video to my wall Commented Jun 21, 2013 at 7:26
  • But where is it defined and what kind of object is it? Can we see the code for that? Commented Jun 21, 2013 at 7:27

3 Answers 3

2

Add android:largeHeap="true" under the application tag in your Android Manifest file. This increases the available memory space at your disposal. However, this only works on API 11+.

answered Jun 21, 2013 at 7:38
Sign up to request clarification or add additional context in comments.

2 Comments

thanks ashwin now it's working but it's taking more time to upload how to reduce the upload time
Compress your video before you send it.
0

Basically, you cannot do it the way you are trying to do. Because you are reading the entire file into memory, you are exhausting the memory at your disposal before it ever gets to the network.

There are a few options you can do to help with this:

  1. You can compress the video, meaning your 15MB can be reduced in size. Depending on the compression, you should be able to load this file into memory. However, this isn't a guarantee and you can still run into issues.

  2. I have checked the Facebook API and it doesn't look like they support streaming data through their Android SDK. This means you need to roll your own. They do have an API to do it on their website (http://developers.facebook.com/docs/reference/api/video/) so you'd have to figure out how to work with that API and then, once you understand it, stream your data to their webservice instead of trying to load it all into a single facebook.request object.

There is a blog post here (http://developers.facebook.com/blog/post/493/) describing how to do it as a POST request. Specifically, quoting from the blog

To publish a video, issue a POST request with the video file attachment as multipart/form-data to https://graph-video.facebook.com/me/videos.

There is a PHP example that you might be able to take key pieces out of and convert to Java.

I would try to do the second approach if I were in your shoes. Hope that helps.

answered Jun 21, 2013 at 7:42

1 Comment

Just so you're aware, the largeHeap option is not a fix. Take a look at the docs (developer.android.com/guide/topics/manifest/…), specifically where it says Most apps should not need this and should instead focus on reducing their overall memory usage for improved performance. Enabling this also does not guarantee a fixed increase in available memory, because some devices are constrained by their total available memory. I would recommend you think about streaming if you want to make a bulletproof app.
0

Sometimes you need to increase the working memory available to eclipse but editting the eclipse.ini file found in the eclipse directory, the last line , the value default to 512m which means only 512mb has been availed as memory to eclipse, increase this and you will have more ram to your eclipse.

answered Jun 21, 2013 at 9:12

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.