0

Hi i am developing an application using adobe air for iOS using flex. i have the user take a snapshot and my intention is to upload the photo to my api. the problem is when compressing the byteArray and then encoding it to a base64 String to send it up the apps freezes for 1-2 minutes.

My question is: is there a way to multithread this process in adove air, so i have it going in the background ?

and from your experience does an adobe native extension use another thread on the device for itself or no, maybe i can handle the background encoding and upload in a native extension.

Thank you all.

Hakim
  • 1,242
  • 1
  • 10
  • 22
  • This is not exactly an answer to your question, but I would use an ane in any case. E.g. i had a similar problem with encoding jpgs on mobile devices. Took about 35 secs in actionscript. With the ane it boiled it down to a few millisecs. So, I don't know about about multithreading, but maybe it's not neccessary, when doing it native, after all. BTW: base64 isn't really a good choice when it comes to pictures, as it creates a significant amount of [overhead](http://stackoverflow.com/questions/11402329/base64-encoded-image-size). Maybe you should consider using something else? – T. Richter Apr 25 '14 at 11:17
  • what other options do i have. it needs to go into XML ? any idea ? – Hakim Apr 25 '14 at 13:43
  • If you have access to the server side, consider using the amf protocoll (BlazeDS or alernatives). If not, you might be forced to use Base64 anyway. – T. Richter Apr 28 '14 at 09:40

1 Answers1

1

AS3, up until recently, was entirely single threaded. As of FP11.4 and AIR 3.4, you have access to Workers, which is essentially offloading tasks to a second thread. Beta support was added to Android in 3.8 or 3.9 and I believe it is out of beta now in 13.0. Workers are not supported by iOS, though. This is, I believe, because they have to cross compile to Objective-C to support iOS at all, so their methods won't work.

You're only option is to load the processing onto an ANE, which may or may not be a good idea. ANEs are meant to behave as a bridge between AIR and native OS APIs. While this would work, I think it goes beyond the scope of what an ANE is intended for.

Unless your photos are insanely large, I would suggest just not doing compression. Resizing photos (using the BitmapData class) is fairly quick on 4S+, so I don't think that is much of an issue (4S is closing in on being 3 years old at this point. Having old hardware means things run less than ideally, so anything older will just have to accept poorer performance)

Worker Documentation

Josh
  • 8,079
  • 3
  • 24
  • 49
  • I read the term 'compression' in this context as 'encoding to png or jpeg', not really as compressing the byteArray (e.g using .zip),so using an ane may be wrong indeed. But when using encoding, it definately make sense, and in this case, it is also used like the design intended, thus using the native encoder rather than the flash one;-) There's an example for the android part [in this question](http://stackoverflow.com/questions/17314467/bitmap-channels-order-different-in-android/17314924#17314924) – T. Richter Apr 28 '14 at 09:50
  • @T.Richter If that is the case, then I think you are right. It is unfortunate that Flash has such terrible encoding support for media of any kind. – Josh Apr 28 '14 at 14:40