Copy link to clipboard
Copied
Dear all,
I am working on an app where I want to (among others) play sound files from the local file system.
I have added a few mp3 files into my .ipa file.
With a small file browser in my app I can select any one of them which returns me a File object.
I then use this File object to do a URLRequest to load the sound:
var req:URLRequest = new URLRequest(file.nativePath);
sound = new Sound();
sound.addEventListener(IOErrorEvent.IO_ERROR, soundLoadError);
sound.addEventListener(Event.COMPLETE, soundLoaded);
sound.load(req);
It works in flash, but fails on the iPAD. Everytime I try to load, I get a IOErrorEvent with error code Error #2032
When I replace new URLRequest(file.nativePath) with URLRequest("http://.../testfile.mp3"), everything works fine!
Any help appreciated.
Is this a matter of Security settings? Can I change those?
Something to do with Sandboxing (whatever that is)?
or something to do with cross-domain access?
I have been looking around for days now and any help would be appreciated!
I am using Flash CS5.5 & AIR 2.7
Thanks, Marcus.
Hi Marcus,
can you try (or maybe have you tried):
var path:String = file.url;
var req:URLRequest = new URLRequest(path);
?
regards,
Peter
Copy link to clipboard
Copied
Did you add the sound file in your iOS settings, under the General tab?
Copy link to clipboard
Copied
Yes, the files were added under the general tab.
In my application, I have a custom browser showing me all my files in my application path. It looks something like this:
[ META-INF ]
[ ...CodeSIgnature ]
[ cs.lproj ]
[ de.proj ]
(etc)
testsound1.mp3 (<- the included mp3 files)
testsound2.mp3
testsound3.mp3
CodeResources
AppIcon.png
(etc)
Copy link to clipboard
Copied
maybe it's not allowed to read from the path:
/var/mobile/Applications/6206ED19-1875-B70B-B41AFF5BDA3D/Main.app/music/TranceOne.mp3
?
Copy link to clipboard
Copied
Hi Marcus,
can you try (or maybe have you tried):
var path:String = file.url;
var req:URLRequest = new URLRequest(path);
?
regards,
Peter
Copy link to clipboard
Copied
yes, that is working.
thank you so much!
var req:URLRequest = new URLRequest(file.url);
Copy link to clipboard
Copied
Hi Marcus,
OK, that's buried somewhere in flash.filesystem.File docs: some api and components in Flash/Air runtime details do require URI/URL *not* native path
(I cannot find specific paragraph right now but I"m sure I've read that in Adobe's docs),
regards,
Peter
Copy link to clipboard
Copied
Hi Peter,
I think you are referring to http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html#applicationDirectory.
Sanika
Copy link to clipboard
Copied
Hi Sanika,
this was something closer to that paragraph for "nativePath":
Some Flex APIs, such as the
source
property of the SWFLoader class, use a URL (theurl
property of a File object), not a native path (thenativePath
property).
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html#nativePath
but that is not exactly what I've read (maybe that was A-blog or post on someone from A-team on his personal blog or post on stackoverflow).
(myself I'm using and providing solutions for paths using FILE protocol - file URI schemes - mostly whenever I can and where it is supported)
regards,
Peter
Copy link to clipboard
Copied
Can't for the life of me figure out why this doesnt work for me. Gives me a StreamError on the var mySound:Sound = newSound() line
var f:File = File.applicationStorageDirectory.resolvePath("/assets/music.mp3");
var resultUrl:String = f.url; // This works to load with a URLLoader
var resultPath:String = f.nativePath; // This works to load with a FileStream operation
trace(resultPath);
var req:URLRequest = new URLRequest(resultUrl);
var mySound:Sound = new Sound();
mySound.load(req);
mySound.play();
Copy link to clipboard
Copied
The issue I believe is the file path to where iOS is storing these files.... has it changed? Assets doesnt seem to work anymore.
Copy link to clipboard
Copied
As long as the assets folder was included when building the app, this seems to be working for me in another app:
var filepath:String = "assets/music.mp3";
var mySound:Sound = new Sound();
mySound.addEventListener(IOErrorEvent.IO_ERROR, onMusicError);
mySound.addEventListener(Event.COMPLETE, onMusicLoaded);
mySound.load(new URLRequest(filepath));
And then calling mySound.play() in the onMusicLoaded function.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now