Copy link to clipboard
Copied
Hi everyone, so I've got a problem, I am making some play btns that will play a sound when it's pressed,
I have the mp3 file in some folder that i refer to in the code:
it plays well when testing, but when i "publish" the app as an .ipa and put it in my iPhone the play button doesn't work,
and i added the folders to the app exactly as it is in the code, which is this:
Random_btn.addEventListener(MouseEvent.CLICK, playRandomSound);
var random_sound:Sound = new Sound();
random_sound.load(new URLRequest("random/randomness/randomsound.mp3"));
var my_randomchannel:SoundChannel = new SoundChannel();
function playRandomjSound(event:MouseEvent):void{
my_randomchannel = random_sound.play();
}
function stopSound(event:MouseEvent):void{
my_randomchannel.stop();
}
Any reason why it shouldn't play that i dont know?
I reapeat i added the "random" folder with the "randomness" sub folder with the "randomsound.mp3" file to the app in the AIR iOS settings..
Thanks for any responses to help
Try to use the File class to reference the file.
var randFile:File = File.applicationDirectory.resolvePath("/random/randomness/randomsound.mp3");
// exist?
if (randFile.exists)
{
var random_sound:Sound = new Sound();
random_sound.load(new URLRequest(randFile.nativePath));
// etc
}
Copy link to clipboard
Copied
Try to use the File class to reference the file.
var randFile:File = File.applicationDirectory.resolvePath("/random/randomness/randomsound.mp3");
// exist?
if (randFile.exists)
{
var random_sound:Sound = new Sound();
random_sound.load(new URLRequest(randFile.nativePath));
// etc
}
Copy link to clipboard
Copied
Thank you, I will try as soon as I can, and I will tell you how it went.
Copy link to clipboard
Copied
Thank you very much . I had the same problem, I tested with your code and works great.
Copy link to clipboard
Copied
Glad it worked for you. It's a little weird at first but soon you'll appreciate properties like .url and .nativePath. Good luck to you both!
Copy link to clipboard
Copied
Mr Sinious
Thanks for your time as above:
I have:___________________________________________
/* AIR 3.6.0.5990 for iOS Flash Pro CS6 Mac OS */
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.media.Sound;
import flash.media.SoundChannel;
var sFile:File = File.applicationDirectory.resolvePath("/alou/sounds/test.mp3");
var channel:SoundChannel = new SoundChannel();
var snd_1:Sound;
if (sFile.exists) {
trace('File there: ');
snd_1 = new Sound();
snd_1.load(URLRequest(sFile.nativePath));
} else {
trace('File NOT found: ');
snd_1 = new p0spop();
}
channel.stop();
channel = snd_1.play();
___________________________________________
from which I get: File NOT found:
if I move the statement: snd_1.load(URLRequest(sFile.nativePath));
outside the if exists, I get: TypeError: Error #1034: Type Coercion failed: cannot convert "/alou/sounds/test.mp3" to flash.net.URLRequest.
If I add the: (new URLRequest...
I get: Attempted access of inaccessible method nativePath through a reference with static type flash.filesystem:File.
I would really appreciate a hand with this as sound is a major component of my current project. Thanks
Copy link to clipboard
Copied
Moving my house to another state, been busy for months, sorry for a late post.
I presume the file is relative to the application install directory? Try simply removing the first / to make the final path: "alou/sounds/test.mp3".
Copy link to clipboard
Copied
Happy new house, or were you actually moving the house itself...
Thanks, I did try that and got:
TypeError: Error #1034: Type Coercion failed: cannot convert "/Users/sesyd/Flash/AuntLou/alou/sounds/test.mp3" to flash.net.URLRequest.
at soundiOS_fla::MainTimeline/frame1()[soundiOS_fla.MainTimeline::frame1:25]
22 if (sFile.exists) {
23 trace('File there: ');
24 snd_1 = new Sound();
25 snd_1.load(URLRequest(sFile.nativePath));
So I'm guessing the file is found, but I have a different problem. Have tried different configurations for the sound, but haven't hit the right one yet.
I'd like to be able to have either library based [or file based in one directory "/alou/sounds/test.mp3"] and if the user records or supplies a different sound file [ "/alou/altSnds/test.mp3"], play that instead of the default.
but I need more help there as well... (I'm writting time line based - not class etc at this stage)
Copy link to clipboard
Copied
A happy move, getting out of renting to buy while the market is still so/so. You just never know how much stuff you have until you have to move alllll of it .
You should be able to use the .url property and you want to make a new URLRequest, not type convert.
e.g.
snd_1.load(new URLRequest(sFile.url));
Although .nativePath should work just fine as well. For common sense code reading I like to stick to the same spec, structure, syntax, etc. URLs in this case.
Copy link to clipboard
Copied
Excellent thank you Sinious, worked a treat.
We have two young boys... (5&7) have moved 9 times since 2006 inc one international. Understand and feel I understand the same syntax better. Thank you
Copy link to clipboard
Copied
You're welcome and I hope you no longer ever need to move . Good luck!