OutOfMemoryError: how best to transfer large video files into a byte array?

by Abdul Mateen » Fri, 09 Apr 2010 05:31:45 GMT


Sponsored Links
 I got the same problem, when I uploaded the videos to Facebook, I have got
the same issue while uploading big files, have you found any workarround,
even I flushed the outstream on every read. but it did not also seems be the
solution.




>



OutOfMemoryError: how best to transfer large video files into a byte array?

by Anna Powell-Smith » Sat, 10 Apr 2010 00:44:27 GMT


 >


Because it's the only way that I know to get from a content Uri to the byte
array that I use to create the FilePart element of the multipart message.

It is possible to create the FilePart element using a File object (this
handles even a 50MB file successfully, though it takes around half an hour
to create, so I don't fancy using it in practice). However, I can't work
from a File object, because I have to use the content Uri that is returned
by ACTION_VIDEO_CAPTURE. Originally I did pass a File Uri as extra output to
ACTION_VIDEO_CAPTURE, but that unfortunately breaks the 'retake' and
'delete' buttons on the video camera.




Thanks, but please could you explain what you mean by that? Perhaps with an
example?

Mark warned that creating buffers tends to clog up memory. Indeed, after
increasing the buffer size to 1MB, as he predicted, I can now handle files
up to about 5MB.

--


Sponsored Links


OutOfMemoryError: how best to transfer large video files into a byte array?

by Anna Powell-Smith » Sat, 10 Apr 2010 02:35:46 GMT


 



Thanks. Constructing a FilePart from a File is actually as easy as this, I
think - but do you think your method would provide some advantage?

    File temp_file = new File(Environment.getExternalStorageDirectory(),
 "myfile.gif");
    FilePart vFile = new FilePart("fileupload", temp_file);

As I say, this works for files of 50MB. The only reason I can't use it is
that I can't construct a File object from an Android content Uri. I have to
use an Android content Uri because that's what the video intent returns.

--



OutOfMemoryError: how best to transfer large video files into a byte array?

by Anna Powell-Smith » Sat, 10 Apr 2010 02:49:46 GMT


 




Ah. If I could transform my content Uri into FileInputStream (will have to
experiment) then I could use your method.

I can convert a content Uri to an InputStream already, so it'll just be
getting from an InputStream to a FileInputStream that might be the
challenge. I'll experiment.

--



OutOfMemoryError: how best to transfer large video files into a byte array?

by Android Development » Thu, 22 Apr 2010 00:03:11 GMT


 Select a fixed buffer size first.

Then start writing the byte array to a file. Once the file size reaches the
buffer size configured, copy that file to a temporary location (a temp
file). Then transfer this temp file to the web server. Once transferred
successfully, make sure to delete this temp file (by calling deleteOnExit()
) when the file was created.

To make this work properly, there have to be 2 threads at work  - the thread
that is writing the byte array to a file and the thread that is doing the
heavy duty stuff in the background - copy to the temp file location and
finally upload it to a server etc. This heavy duty thread waits on a
condition (waits for the file to reach the buffer size configured to start
the transfer).

I hope this makes sense...just sharing my thoughts aloud.

Best Regards
Indodroid.

On Sat, Apr 10, 2010 at 12:19 AM, Anna Powell-Smith <





>



Other Threads

1. how to allow user call Gallery to launch or show image and video ?

Dear All,
I need help,
I try using  Intent intent = new
Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
but that only show images not video, how to allow user call Gallery to
launch or show both images and videos ?

Regards
setyabudhi

-- 

2. What's the FlashLitePlugin.apk supposed to do?

I just installed this plugin <http://www.mediafire.com/?ix2iwdm4otl> and
then try to play my *flash_lite.swf* in the browser,but nothing happens.


Anyone knows how to use this plugin?

-- 

3. adb install speed is very slow

4. Implement Progress Bar for File Download

5. Monkey tool does not seem to run on all defined packages.

6. How to add radio buttons in android search

7. How to avoid out of memory error in android