Loading External Picture in air for android - android

I need load images from a folder in application directory created in sd Card of mobile android
This is working in PC, but not in mobile version
Some solution ?
var imagesFin:File = File.applicationStorageDirectory.resolvePath("appImages/");
var files:Array = imagesFin.getDirectoryListing();
for (var i:uint = 0; i < files.length; i++){
var picLoader = new Loader();
picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadPicture);
picLoader.load(new URLRequest(files[i].nativePath));
}
function loadPicture(event:Event):void {
var imgAtual = event.target.content;
ContainerImagesList.addChild(imgAtual);
}

This work for me:
var bytes:ByteArray = new ByteArray();
var myFileStream:FileStream = new FileStream();
var myFile:File = File.documentsDirectory.resolvePath(YOUR_PATH);
myFileStream.addEventListener(Event.COMPLETE, fileCompleteHandler)
myFileStream.openAsync(myFile, FileMode.READ);
function fileCompleteHandler(event:Event):void
{
myFileStream.readBytes(bytes);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader.loadBytes(bytes);
function imageLoaded(e:Event):void
{
addChild(Bitmap(loader.content));
myFileStream.removeEventListener(Event.COMPLETE, fileCompleteHandler);
myFileStream.close();
}
}
Cheers!

In iOS I never use resolvePath. I just use a relative url like "images/photo.jpg" and it works perfectly on any iOS device.
Instead of resolvePath you could also use URL schemes. It's a lot simpler "app:/images/photo.jpg" or "app-storage:/settings/prefs.xml".
http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7fe4.html
This is what I do to get all images in my image file cache
var imageFolder:File = new File("app:/img");
var getfiles:Array = imageFolder.getDirectoryListing();

Related

unload externally loaded swf

In my app, I have loaded some external swf files. It's a game files so for avoiding sandbox error I use the follwing code:
var file:File = File.documentsDirectory.resolvePath("myFilePath");
var toLoadUrl = file.url;
var myUrl:URLRequest;
myUrl = new URLRequest(toLoadUrl);
var inFileStream:FileStream = new FileStream();
inFileStream.open(file, FileMode.READ);
var swfBytes:ByteArray = new ByteArray();
inFileStream.readBytes(swfBytes);
inFileStream.close();
var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loaderContext.allowLoadBytesCodeExecution = true;
loaderContext.allowCodeImport = true;
myLoader = new Loader();
myLoader.loadBytes(swfBytes, loaderContext);
//myLoader.load(myUrl, loaderContext);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadComplete_swf);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop, false, 0, true);
myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadingError);
And to unload the file, I've used:
if(myLoader)
{
trace("Unloaded");
myLoader.unloadAndStop(true);
myLoader.unload();
}
while(MovieClip(root).holder.numChildren > 0)
{
var item:DisplayObject = MovieClip(root).holder.removeChildAt(0);
trace("Removed");
}
if(contains(myLoader))
{
trace("Remove child");
removeChild(myLoader);
}
It works but only for one time. After that It keeps stacking all the files even the codes to remove it has been executed. I can still hear the sounds and the codes from the swf files are still running. Is there any problem with the above code? How do I completely remove the loaded files? Any help would be appreciated.

Web Audio Api biquadFilter in Android needs extra configuration?

Here says the Web audio API works in Chrome for Android, and here I have tested CM Browser, Chrome and CyanogenMod default Android 5.1.1 browsers, and all pass the tests (specially the biquadNode one).
But When I open this codepen with an eq (biquadNode), I can hear the music but not the eq working.
Does biquadNode works in android? any special implementation is needed?
*Code pen required to post
var context = new AudioContext();
var mediaElement = document.getElementById('player');
var sourceNode = context.createMediaElementSource(mediaElement);
// EQ Properties
//
var gainDb = -40.0;
var bandSplit = [360,3600];
var hBand = context.createBiquadFilter();
hBand.type = "lowshelf";
hBand.frequency.value = bandSplit[0];
hBand.gain.value = gainDb;
var hInvert = context.createGain();
hInvert.gain.value = -1.0;
var mBand = context.createGain();
var lBand = context.createBiquadFilter();
lBand.type = "highshelf";
lBand.frequency.value = bandSplit[1];
lBand.gain.value = gainDb;
var lInvert = context.createGain();
lInvert.gain.value = -1.0;
sourceNode.connect(lBand);
sourceNode.connect(mBand);
sourceNode.connect(hBand);
hBand.connect(hInvert);
lBand.connect(lInvert);
hInvert.connect(mBand);
lInvert.connect(mBand);
var lGain = context.createGain();
var mGain = context.createGain();
var hGain = context.createGain();
lBand.connect(lGain);
mBand.connect(mGain);
hBand.connect(hGain);
var sum = context.createGain();
lGain.connect(sum);
mGain.connect(sum);
hGain.connect(sum);
sum.connect(context.destination);
// Input
//
function changeGain(string,type)
{
var value = parseFloat(string) / 100.0;
switch(type)
{
case 'lowGain': lGain.gain.value = value; break;
case 'midGain': mGain.gain.value = value; break;
case 'highGain': hGain.gain.value = value; break;
}
}
createMediaElementSource in Chrome on Android doesn't work in general. But if you have a recent build of Chrome (49 and later?), you can go to chrome://flags and enable the unified media pipeline option. That will make createMediaElementSource work like on desktop.

Re-loading Swf file from sdcard as3 Android

I am working on an android app where I wish to download swf files from an external server, save them to sdcard and load them later in the app. Downloading works fine and the swf is saved in the application directory. Here is my code that loads the swf from the sdcard :
var myloader:Loader = new Loader();
var myhomeButton:btnHome = new btnHome();
addChild(myloader);
var swfFilePath:File = File.applicationStorageDirectory.resolvePath("Android/data/myswffile.swf");
var inFileStream:FileStream = new FileStream();
inFileStream.open(swfFilePath, FileMode.READ);
var swfBytes:ByteArray = new ByteArray();
inFileStream.readBytes(swfBytes);
inFileStream.close();
var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loaderContext.allowCodeImport = true;
myloader.contentLoaderInfo.addEventListener(Event.COMPLETE, mycompleteHandler);
myloader.loadBytes(swfBytes, loaderContext);
function mycompleteHandler(evt:Event):void
{
myloader.contentLoaderInfo.removeEventListener(Event.COMPLETE, mycompleteHandler);
addChild(myhomeButton);
myhomeButton.height = _height * 0.08;
myhomeButton.width = myhomeButton.height;
myhomeButton.x = 10;
myhomeButton.y = 10;
myhomeButton.addEventListener(MouseEvent.CLICK, myexitfftn);
}
function myexitftn(evt:Event):void
{
myloader.unloadAndStop(true);
removeChild(myhomeButton);
gotoAndStop(1, "SomeOtherFrame");
}
the problem is when I click the exit button the swf unloads but when I reload it, it starts from the second frame of the loaded swf, the third time from the third frame and so on... Where am I going wrong or what is an alternative solution, please guide.
Try, addChild(myloader) in Complete handler and removeChild and null while exiting, so that loaded swf is completely removed from the memory like so:
function mycompleteHandler(evt:Event):void
{
myloader.contentLoaderInfo.removeEventListener(Event.COMPLETE, mycompleteHandler);
addChild(myloader);
//... Rest of code remains same
}
function myexitftn(evt:Event):void
{
myloader.unloadAndStop();
removeChild(myloader);
myloader = null;
removeChild(myhomeButton);
gotoAndStop(1, "SomeOtherFrame");
}

Displaying contact image in HTML using PhoneGap

I am trying to display the image with URL content://com.android.contacts/contacts/1/photo in the image element of HTML page.
Although it's a old problem, Can anyone please provide me a complete example to display a contact image in img element using PhoneGap.
Thanks in advance,
prodeveloper.
I read a lot on this probleme and the problem seems to be solved on the cordova 3.2.0
here is my code.
You do not need to create a tempory image or something else.
var init = function () {
var options = new ContactFindOptions();
options.filter = ""; // empty search string returns all contacts
options.multiple = true; // return multiple results
var filter = ["displayName",
"phoneNumbers",
"photos"];
navigator.contacts.find(filter, onSuccess, onError, options);
};
function onSuccess(contacts) {
var contactPhoto;
for (var i = 0; i < contacts.length; i++) {
if (contacts[i].displayName && contacts[i].phoneNumbers) {
contactPhoto = defaultvalue;
if (contacts[i].photos) {
for (var j = 0; j < contacts[i].photos.length; j++)
if (contacts[i].photos[j].value) {
contactPhoto = contacts[i].photos[j].value;
break;
}
}
showContactsModel.Contacts.add(
{
displayName: contacts[i].displayName,
phoneNumbers:contacts[i].phoneNumbers,
photo: contactPhoto
});
}
}
}
and my binding
<img data-bind="attr:{src: photo}" alt="something.png" />
you can directly use
<img src="content://com.android.contacts/contacts/1502/photo" alt="Oops!!">
once you have the url of image !

Issue accessing local xml files in apk file - Air for Android

This is my first time really getting my teeth into Air for Android so please forgive me if this issue has been covered already. If it has then I've been unable to find it.
So I have an application that loads and displays xml data.
In the app I've got code to check if wiFi or equivalent is available and if so then pull live xml file and if not then pull the local xml file that was packaged with the application.
The app works fine if I am pulling in the xml from the live url but not if pulling from local.
After doing some research I discovered that when pulling in local file then Air for Android works slightly differently. So I need to resolve the application directory.
I did this and still no joy.
After a bit more research I read some post's that said I should use fileStream()
Tried this and still nada :(
All the time whilst testing in Flash IDE it works as intended.
If I had any more hair left I would be pulling it out right now!
The local xml file is set in the "includes"
Sample code below I am using for testing
var subURL:String = "xml_feeds/myxmlfile.xml"
var fileStream:FileStream = new FileStream();
var file:File = File.applicationDirectory.resolvePath(subURL);
fileStream.addEventListener(Event.COMPLETE, processXMLData);
fileStream.openAsync(file, FileMode.READ);
MovieClip(parent).txStates.text = file.url+" - TRYING"
var prefsXML:XML = new XML()
function processXMLData(event:Event):void{
MovieClip(parent).txStates.text = file.url+" - OPEN"
prefsXML = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
var tempArr:Array = new Array();
var reportCount:Number = prefsXML.row.column.length()
for (var i = 0; i < reportCount; i++) {
var rName:String = prefsXML.row.column[i].#name.toString();
var rValue:String = prefsXML.row.column[i].toString();
var rTitle:String = prefsXML.row.column[i].#name.toString()
tempArr.push([rName, rValue, rTitle]);
}
showData()
fileStream.close();
}
Is there anything I've missed?
UPDATE: 21/08/12
No idea what is going on with this. Here is the code i now have to use in order to load in the local xml file. Seems rather long winded
function listing():void{
var folders:Array = new Array();
folders = File.applicationDirectory.getDirectoryListing();
for(var i:Number =0;i<folders.length;i++){
if(folders[i].isDirectory){
if(folders[i].name=="xml_feeds"){
var files:Array = new Array();
files = folders[i].getDirectoryListing();
for(var j:Number=0;j<files.length;j++){
if(files[j].name=="CTSection2.xml"){
fileStream.openAsync(files[j], FileMode.READ);
fileStream.addEventListener(Event.COMPLETE, processXMLData);
fileStream.addEventListener(IOErrorEvent.IO_ERROR, localXMLFailLoad);
}
}
}
}
}
}

Categories

Resources