This content has been marked as final.
Show 6 replies
-
1. Re: playing local sound file
Jeff Swartz Feb 26, 2009 11:12 AM (in response to kamckng)Re. "I won't necessarily know the path to the file because I need to use things like the storage directory":
- You do not *need* to use the application storage directory. But it is a good place to store application-specific data. AIR can load files from other locations.
- If you do want to use the application storage directory, your code looks good. -
2. playing local sound file
paus akid Mar 2, 2009 8:40 AM (in response to Jeff Swartz)I'm trying to do the same thing as kamckng. On WINXP it's working, but on OSX I get an 'app:' in front of my mp3s file.nativePath. here's my example code
var file:File = new File();
file = file.resolvePath(currentRandomSong);
var req:URLRequest = new URLRequest(file.nativePath);
songCurrent = new Sound();
songCurrent.addEventListener(IOErrorEvent.IO_ERROR, onSoundError);
songCurrent.addEventListener(Event.COMPLETE, onSoundLoaded);
songCurrent.load(req);
which throws an IOErrorEvent:
Error #2032: Stream Error. URL: app:/Users/starpause/mp3s/song.mp3
/Users/starpause/mp3s/song.mp3 does exist on the filesystem
any ideas? -
3. Re: playing local sound file
kamckng Mar 2, 2009 11:53 AM (in response to kamckng)I don't know much about OSX at all. Could you just check for an instance of app: in the nativePath and just filter it out if it's there? -
4. Re: playing local sound file
paus akid Mar 2, 2009 12:36 PM (in response to kamckng)@kamckng unfortunately no, 'app:' isn't on file.nativePath, it's added by the URLRequest and URLRequests can't be manipulated by strings. -
5. Re: playing local sound file
Joe ... Ward Mar 2, 2009 1:13 PM (in response to paus akid)@ paus akid,
There are two things wrong here.
One, you should never use a nativePath in place of a URL. This happens to work on Windows because the nativePath is interpreted as an absolute path. However, on Mac and Linux, a nativePath is indistinguishable from a relative URL. Since relative URLs are resolved against the application directory (in general), you get the app:/ URL scheme. So change:
var req:URLRequest = new URLRequest(file.nativePath);
to:
var req:URLRequest = new URLRequest(file.url);
The second issue is that you don't initialize your file object before using it to resolve a second path. Instead of:
var file:File = new File();
file = file.resolvePath(currentRandomSong);
You should do something like this (using the appropriate directory):
var file:File = File.usersDirectory("path/to/mp3");
See
Developing cross-platform AIR applications for more information. -
6. playing local sound file
paus akid Mar 3, 2009 4:50 PM (in response to kamckng)@Joe thanks very much!
.url vs .nativePath was exactly my problem... so i'm now storing file handles using nativePath but using a file handle to extract and pass a url to the loaders in my application.
thanks for the article as well, interesting read.



