0

Making an AS3 app for android that uses camera roll to load, select and then use an image.

The cameraroll browser works fine, but when the image is selected, the app crashes - almost every time - as it has worked on a handful of occasions (!?!) We assumed a memory issue and attempted to close all other windows / use smaller photos in the camera roll etc. and try different devices - but cannot recreate success consistently. Cannot find another ANE that works either

It fails at the point where the photo has been selected, and RESTARTS the app...

here's the relevant code, any help appreciated.

public function openGallery():void {
            var cameraRoll:CameraRoll = new CameraRoll(); 
            if(CameraRoll.supportsBrowseForImage) { 
                cameraRoll.addEventListener(MediaEvent.SELECT, imageSelected); 
                cameraRoll.addEventListener(flash.events.Event.CANCEL, browseCanceled); 
                cameraRoll.addEventListener(flash.events.ErrorEvent.ERROR, mediaError); 
                cameraRoll.browseForImage();
            } 
            else { trace( "Image browsing is not supported on this device."); } 
        }

private function imageSelected(event:MediaEvent):void { 
            trace("Media selected..."); 
            var imagePromise:MediaPromise = event.data as MediaPromise; 
            _dataSource = imagePromise.open(); 
            if(imagePromise.isAsync) { 
                trace("Asynchronous media promise."); 
                var eventSource:IEventDispatcher = _dataSource as IEventDispatcher; 
                eventSource.addEventListener(flash.events.Event.COMPLETE, onMediaLoaded); 
            } else { 
                trace("Synchronous media promise."); 
                readMediaData(); 
            }
        } 

private function onMediaLoaded(event:flash.events.Event):void{
            trace("Media load complete");  

            _mediaBytes = new ByteArray();            
            _dataSource.readBytes(_mediaBytes);                     
            _tempDir = File.createTempDirectory();            
            var now:Date = new Date();            
            var filename:String;            
            filename = now.fullYear + now.month + now.day+now.hours + now.minutes + now.seconds + ".JPG";            
            _file = _tempDir.resolvePath(filename);

            //writing temporal file to display image            
            _stream = new FileStream();            
            _stream.open(_file,FileMode.WRITE);            
            _stream.writeBytes(_mediaBytes);            
            _stream.close();

            if(_file.exists){

                _imageLoader = new Loader();                
                _imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onMediaLoadedBitmapData);                
                _imageLoader.loadBytes(_mediaBytes);

            }

        }   

        private function onMediaLoadedBitmapData(event:Event):void{
            trace("onMediaLoadedBitmapData");
            var loaderInfo:LoaderInfo = LoaderInfo(event.target);            
            _bitmapData = new BitmapData(loaderInfo.width,loaderInfo.height,false,0xFFFFFF);            
            _bitmapData.draw(loaderInfo.loader);
                        addPictureToScreen();
        }
mdk
  • 133
  • 1
  • 7

1 Answers1

0

I had a similar thing happen in Air for iOS but it was related to picking large images. I just checked the dimensions of the chosen image and then used a scalar matrix if they were past a certain point. Sounds like you've thought about this but maybe look further into that?