Skip navigation
Currently Being Moderated

Playing external sound (iOS app)

Aug 31, 2012 6:00 AM

Tags: #air #app #as3 #3.0 #ios #button #sound #action #3 #actionscript #code #as3.0 #random #ac3 #actionscript3 #ipa

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

 
Replies
  • Currently Being Moderated
    Aug 31, 2012 9:26 AM   in reply to iden_tidad

    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

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 18, 2012 10:54 PM   in reply to sinious

    Thank you very much . I had the same problem, I tested with your code and works great.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 19, 2012 7:55 AM   in reply to l_avanti

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2013 4:47 PM   in reply to sinious

    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

     

     

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2013 7:29 AM   in reply to amandasyd

    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".

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2013 5:59 PM   in reply to sinious

    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)

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 12, 2013 10:27 AM   in reply to amandasyd

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 12, 2013 3:58 PM   in reply to sinious

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 13, 2013 5:02 AM   in reply to amandasyd

    You're welcome and I hope you no longer ever need to move . Good luck!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points