Playing local sound file

I need to play an mp3 file in my AIR app. But I won't
necessarily know the path to the file because I need to use things
like the storage directory. So, would I have to do something like
this to get that done:
var file:File =
File.applicationStorageDirectory.resolvePath("path/to/mp3");
var urlRequest:URLRequest = new URLRequest(file.nativePath);
and then load the sound from that? Or is there some way that
AIR has provided to skip the first step?
Thanks!
Kyle

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

Similar Messages

  • How do i play two sound file one after another

    Hi All,
    How do i play two sound file one after another using single AudioClip Component?.
    Advance in thanks
    Manivel

    AudioClip gives you very little control over what happens to the sound, it also isn't capable of playing long clips or waiting until a clip ends. It will play multiple clips over top of each other.
    To do what you want you should use the facilities of javax.sound. Here's a post with an example: http://forum.java.sun.com/thread.jspa?forumID=513&threadID=450768
    There is also a tutorial, but its example fails for long clips.

  • Standalone app (AIR?) for playing local FLV files

    Can someone point me to a desktop app (Windows and Mac) that can play local FLV files?
    Thanks!

    I don't know about an AIR application but you could make any Flash video player you want to create into a stand-alone simply by publishing it as a "Projector" file. So create your own custom player and include your own branding in the design.
    Or does this need to have a "browse to file" capability? Have never added that to a vid player so I'm not sure how that would work out.
    But here is a simple little .flv video editor that I sometimes use to check out video files:
    http://download.cnet.com/Moyea-FLV-Editor-Lite/3000-2168_4-10912717.html
    It's a video editor, not just a player... but it's free, and allows you to open and play .flv files.... maybe a temp solution ??
    Best wishes,
    Adninjastrato

  • Help playing a sound file please...

    i am trying to play a sound file everytime a button is clicked. the sound will play the first time the button is clicked but wont play after that. how can i get the sound file to play everytime the button is clicked?? here's how i play the sound file...
    InputStream in = new FileInputStream(sound.wav);
    AudioStream as = new AudioStream(in);
    // in the button action event...
    AudioPlayer.player.start(as);
    i tried adding this line... AudioPlayer.player.stop(as);...before the...AudioPlayer.player.start(as); -- the sound file still only plays once
    any help appreciated...thanks

    Hi there,
    Is there a class AudioPlayer in the API or is it yours. Anyway, your class must implement AudioClip interface. Then call yourClass.play(as); You dont need to stop, each time you call play(), it restarts. Try and let me know.
    cheers

  • Differences between the 2 ways to play local swf files in flash player

    There are 2 ways to allow the flash player to play local swf files:
    Add the directory/file of the swf to the Global Flash Player Trust directory. http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9 b90204-7c95.html
    Add the directory/file of the swf to the Trusted Location Settings in the Local Settings Manager.http://help.adobe.com/en_US/FlashPlayer/LSM/WS6aa5ec234ff3f285139dc56112e3786b68c-7ff0.htm l#WS6aa5ec234ff3f285139dc56112e3786b68c-7fea
    Adobe doesn't mentioned in the document what's the differences between these 2 methods, and they look has the same effect. But when I'm doing it on OS X, Safari 6.1, the first method doesn't work (It was working when I was using Safari 6.0). And then I tried method 2, it works…
    So I'd like to ask what are the differences between these 2 methods to play local swf files?

    For playing local SWF files, Download the Macintosh Flash Player 11.9 Projector
    It's a standalone app. Just copy it to your Applications folder. Launch it, and drag the SWF to the Dock icon. It'll play.

  • Problem, trying to play many sound files

    hello,
    I did not find a specific answer to my question in most of the archives and so I am posting here.
    my problem is that I have to play a sound when mouse moves over an object and another sound when the same object is clicked.
    there are many such items on the screen and so it is expected that when the mouse entered from the mouse listener is fired, the sound must play.
    but what really happens is that when the mouse moves over the first object the sound plays all right. but there is no sound played when the mouse click happens.
    I have properly loaded the sound files and I am sure that the code is right.
    infact the major thing that has frustrated me is that if I move the mouse on an opject (an icon) the sound is properly played. and if I wait for a long time and then move the mouse on another icon the other sound is played as well. but if I move the mouse quickly from one object to another no sound is played for the second object. or if I click the mouse on an icon after a long holt even the click sound playes.
    what could be the problem. why is it that sound only play when the actions are done after long haults?
    is it an issue of java performance. should I try to do the sound playing stuff in different threads for each icon's mouse events?
    I also tried to stop the file on the mouse exit method to make sure that there is no sound left playing.
    this game is depending a lot on mouse movements with sounds and so I have to get the sounds playing at the same time mouse moves over the objects.
    I use the audioClip to load my sounds with the method in the applet class.
    I really don't know abt the latest java media api and will like to know if that is what I must use for my task or audioClip is ok with me.
    thanks
    Krishnakant.

    I dont know exactly, but I dont know if applets support various files at one time.
    Have your tried to do that with javax.media or with javax.sound.sampled?
    Or could your post the code?
    R. Hollenstein

  • Mail app no longer plays QuickTime sound files.

    Before upgrading to Mountain Lion, I was able to play sound files attached to mail within the app.
    In other words, if someone sent me a sound file, it would appear as a QuickTime sound within the body of the email and I could play it.
    That was a very nice feature.
    Now sound files will not play within the mail window. Instead, I need an external player such as QuickTime Player or iTunes.
    How can I get that feature back?

    What specific sound file types will not play as Mail attachments in Mountain Lion?
    I just sent an .m4r (ringtone), mp3, and .m4a (iTunes aac music) files as Mail attachments. The first appeared as an icon that played via QuickLook from within Mail. The second two appeared as black, QuickTime styled, embedded music play bar attachments. They played back flawlessly.
    Have you installed any application recently that may have hi-jacked the default QuickTime audio playback? It would have done so silently, or popped up a dialog requesting to perform the hi-jack on a list of music file formats.
    You may have to select each particular audio file format in Finder Get Info and restore QuickTime in the Open with section on that panel.

  • How to play wikipedia sound files (Ogg) in Safari 6.0.3?

    I'm pretty sure the answer to this one is that it can't be done, but just in case I've missed something in my web searching. I used to be able to play them under OSX 10.6.8. For instance, these sound files: http://en.wikipedia.org/wiki/Beethoven_symphony_5

    Please link to a page you're having trouble with, if possible.

  • Problem with playing a sound file.

    Hi,
    I simply want to play a sound by a button click. I imported
    <AVFoundation/AVAudioPlayer.h>. The code block is here:
    In .h file:
    #import <UIKit/UIKit.h>
    #import <AVFoundation/AVAudioPlayer.h>
    @interface PlaySoundViewController : UIViewController <AVAudioPlayerDelegate>
    in .m file:
    -(IBAction)btnPlay:(id)sender
        //Get the filename of the sound file:
        NSString *path = [[NSBundle mainBundle] pathForResource:@"REC001" ofType:@"MP3"];
        AVAudioPlayer* thePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];//error here as it will compile if I commented it (and two line after) out.
        thePlayer.delegate = self;
        [thePlayer play];   
    Everything looks fine but it failed when I tried to run it. Looks like it cannot find my sound file "REC001.MP3". I put it in folder ".../PlaySound/Resource Files/SoundFiles/REC001.MP3", and "PlaySound" is my project name. However the path returned is ".../PlaySound/REC001.MP3". I guess this is why it cannot find the object. But it didn't work even I put the sound file under "PlaySound" directly. Anyone has a solution?
    Thanks.
    Regards,
    Taizhi

    Hi Mark,
    Thanks for the reply. Based on your instruction, I checked and I can see the sound files in Build Phases. The location is ".../PlaySound/SoundFiles/REC001.MP3". I don't know why it ignores folder "Resource Files". I guess that is the way it is as I also can see other images in different folders which are shown properly in the project.
    The detailed error message is here:
    Ld "/Users/greatzhi2001/Library/Developer/Xcode/DerivedData/PlaySound-anydnuuxbpxz lqfodwbuqqjwjzcd/Build/Products/Debug-iphonesimulator/PlaySound.app/PlaySound" normal i386
        cd "/Users/greatzhi2001/Desktop/iProjects/PlaySound"
        setenv MACOSX_DEPLOYMENT_TARGET 10.6
        setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr /bin:/usr/bin:/bin:/usr/sbin:/sbin"
        /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3 .sdk -L/Users/greatzhi2001/Library/Developer/Xcode/DerivedData/PlaySound-anydnuuxbpx zlqfodwbuqqjwjzcd/Build/Products/Debug-iphonesimulator -F/Users/greatzhi2001/Library/Developer/Xcode/DerivedData/PlaySound-anydnuuxbpx zlqfodwbuqqjwjzcd/Build/Products/Debug-iphonesimulator "-F/Users/greatzhi2001/Desktop/iProjects/PlaySound" -filelist "/Users/greatzhi2001/Library/Developer/Xcode/DerivedData/PlaySound-anydnuuxbpxz lqfodwbuqqjwjzcd/Build/Intermediates/PlaySound.build/Debug-iphonesimulator/PlayS ound.build/Objects-normal/i386/PlaySound.LinkFileList" -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework UIKit -framework Foundation -framework CoreGraphics -o "/Users/greatzhi2001/Library/Developer/Xcode/DerivedData/PlaySound-anydnuuxbpxz lqfodwbuqqjwjzcd/Build/Products/Debug-iphonesimulator/PlaySound.app/PlaySound"
    Undefined symbols for architecture i386:
      "_OBJC_CLASS_$_AVAudioPlayer", referenced from:
          objc-class-ref in PlaySoundViewController.o
    ld: symbol(s) not found for architecture i386
    collect2: ld returned 1 exit status
    Is the framework AVFoundation I added wrong? Thanks.
    Regards,
    Taizhi

  • Please tell me how to automatically play a sound file in a PDF slideshow?Da

    I use PS CS3, LR2, and now I purchased Acrobat 9.1 Pro.  My intent is to create an image based full screen automatic slideshow WITH SOUND.  I have everything working well but I can't figure out how to get the sound file to simply play along with the images.  I do not want the viewer to have to press anything to hear the sounds.  The sound file should simply play along with the image(s).  I would like to be able to time the sound file to the images as well.
    I will appreciate any pointers you may have.
    Thanks...

    To do this reliably the document has to be in the list of the client applications list of trusted documents.  You get this prompt when you attempt to play a sound.  The other way is to actually set the Multimedia Trust (legacy) preference on each client for each type of Player application.  While this might seem a bit of a task it's meant to protect the user.

  • Playing local authorware files in IE 7

    I cannot play published Authorware files in the Internet
    Explorer 7 from my local computer. I get error messages "invalid
    map files etc". The published files play correctly in a local
    Mozilla browser and also if I upload them on a server and play them
    online with Internet Explorer 7. Is there a local setting, which
    solves the problem? Normally I like to test the files on my
    computer before uploading all the published files.
    Thanks
    Ruth

    "ivoryruth" <[email protected]> wrote in
    message
    news:f1s522$ctd$[email protected]..
    >I cannot play published Authorware files in the Internet
    Explorer 7 from my
    > local computer. I get error messages "invalid map files
    etc". The
    > published
    > files play correctly in a local Mozilla browser and also
    if I upload them
    > on a
    > server and play them online with Internet Explorer 7. Is
    there a local
    > setting,
    > which solves the problem? Normally I like to test the
    files on my computer
    > before uploading all the published files.
    There is no local setting, as such. What you must do is
    reference the aam
    file as a literal folder path - File://c:/work/test.aam
    (that's not quite
    right, the File:// should be a little different), instead of
    the default
    relative reference that is used by Authorware.
    Alternatively, I think you can still test by clicking on the
    aam file
    instead of the htm ...
    Steve
    EuroTAAC eLearning 2007
    http://www.eurotaac.com
    Adobe Community Expert: Authorware, Flash Mobile and Devices
    My blog -
    http://stevehoward.blogspot.com/

  • Playing mp4 sound files

    I am trying to make my code play a sound when a button is pressed. 
    At the moment I am using the play sound file block, but this block only accepts files in a .WAV format. 
    I am creating this program for someone who is not great with computers. Their easiest way to record sounds to be played saves them in an MP4 format.
    Having to make them convert the files to .WAV would be very difficult and frustraiting for them.
    What I am asking is if there is a way to play a MP4 file in labview, or a way to programatically convert a MP4 file into a .WAV file for the play sound file block.
    Thanks for your time. 

    This might work.
    Attachments:
    WindowsMedia_Player.vi ‏148 KB

  • How to play downloaded sound files?

    I 'save as' sound files from a nature recordist's group - usually mp3s- but I cant play them.
    Help? I know this is the place.
    Thanks
    ibook G4, B&W G3, Pismo G3   Mac OS X (10.4)   0S 9.2, Peak Le

    As Duane says, iTunes should play MP3. If you have downloaded to, say, the desktop, iTunes will not automatically play it. But if you double click it, iTunes should automatically open and import the song as long as iTunes has been set as your default player. If that doesn't work, occasionally you need to drag & drop the file into an open iTunes window. If that doesn't work the file is corrupt or isn't MP3 even if the download says it is.
    Have fun!
    Adrian

  • Play multiple sound files in different frames from library in flash

    My assessment task for college is to create a webpage of my work.  So far it runs brilliantly except for this.  I only need this to be working in like 2 days!  Help!
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Carolyns_Media_Portfolio_Scene1_fla::MainTimeline/frame5()
    at flash.display::MovieClip/gotoAndStop()
    Trying to be able to play sound clips from the library with the option to play and stop the sound file. Each sound has its own frame, with stop and play buttons. I can run the first sound file perfectly being able to start and stop it but when trying to play the next sound it creates the above error on output. I have dead buttons as well on the second sound.
    The top buttons take you to each scene
    The script runs from frame 5.
    import flash.events.MouseEvent;
    **buTrivia.addEventListener(MouseEvent.CLICK,clickListener7);
    function clickListener7(event:MouseEvent):void {
    SoundMixer.stopAll()
    gotoAndStop("trivia");
    buToyRA.addEventListener(MouseEvent.CLICK,clickListener8);
    function clickListener8(event:MouseEvent):void {
    SoundMixer.stopAll()
    gotoAndStop("toyminatorRA");
    buCaroline.addEventListener(MouseEvent.CLICK,clickListener9);
    function clickListener9(event:MouseEvent):void {
    SoundMixer.stopAll()
    gotoAndStop("caroline");
    buServerDown.addEventListener(MouseEvent.CLICK,clickListener10);
    function clickListener10(event:MouseEvent):void {
    SoundMixer.stopAll()
    gotoAndStop("serverdown");
    This was the script I found and edited.  Only Trivia works
    stop();
    var triviaSound:trivia = new trivia()
    var triviaChannel:SoundChannel = new SoundChannel();
    buplay1.addEventListener(MouseEvent.CLICK, playSound1);
    buStop1.addEventListener(MouseEvent.CLICK, stopSound1)
    function playSound1(event:MouseEvent):void
    triviaSound.play();
    function stopSound1(event:MouseEvent):void
    SoundMixer.stopAll()
    gotoAndStop("trivia");
    /*buplay2.addEventListener(MouseEvent.CLICK, playSound2);
    bustop2.addEventListener(MouseEvent.CLICK, stopSound2)
    var toysSound:toys = new toys();
    var toysChannel:SoundChannel = new SoundChannel();
    function playSound2(event:MouseEvent):void
    toysSound.play();
    function stopSound2(event:MouseEvent):void
    SoundMixer.stopAll()
    gotoAndStop("toyminatorRA");
    Basically I want to play all the sounds, from the library, individually in different frames using the option to play and stop that sound.  I found the above script but only works for one sound.  I am new at scripting in flash so any help or even a better script option would be awesome.  Thank you

    The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....
    - is declared but not instantiated
    - doesn't have an instance name (or the instance name is mispelled)
    - does not exist in the frame where that code is trying to talk to it
    - is animated into place but is not assigned instance names in every keyframe for it
    - is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).
    If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

  • How can i play a sound file in form 10g

    hi every body ,
    would any one help me with my problem
    *I 'd like to play a soend wave file _ say when press a button _*
    In forms 6i
    it was too easy,
    Read_sound_File('c:\aaa.wav', 'wav', 'emp.sound');
    Go_Item('emp.sound ');
    play_sound('emp.sound');
    But it doesn't work in 10g
    and there is n't read_sound_file in help of 10g
    is there any compatability with this instruction in forms 10g
    or how can i use sound file in 10g
    is it with webUtil ( i' ve configured it correctly )
    *or with java beans _ plz help me with it _*
    Thanks _ waiting for u answers _ plzzzzzzzzzzzzzzzz

         I 'd like to play a soend wave file _ say when press a button package sound;
    import oracle.forms.ui.VButton;
    import java.applet.AudioClip;
    import java.applet.Applet;
    import java.net.URL;
    import oracle.forms.properties.ID;
    public class sound extends VButton
    public final static ID PLAY = ID.registerProperty("PLAY");
    public String sou_loc = "FILE:///C:\EAM_original.wav" ;
    public sound()
    public boolean setProperty(ID p0, Object p1)
    if (p0==PLAY)
    { try
    sou_loc = p1.toString();
    URL sou = new URL(sou_loc);
    AudioClip clip = Applet.newAudioClip(sou);
    clip.play();
    } catch (Exception ex)
    {ex.printStackTrace();}
    return super.setProperty(p0, p1);
    }

Maybe you are looking for

  • Error in J1IIN for create Excise for Factory sale

    Hi, I need your help regarding Sales excise. The scenario is I have created PO and done with MIGO so Part I and Part II register are getting hit BED is showing. My problem is now I have to use the amout for sales cycle i.e after genrating accounting

  • FCP 7.0.3 and Canon XL1s

    I have just purchased a Canon XL1s and am having huge problems capturing footage of a decent quality using FCP 7.0.3 Having done some searching about the Canon camera and FCP i used, from the 'Easy Setup' menu Format: PAL Use: DV-Pal FireWire Basic W

  • EText PERIODIC_SEQUENCE

    Hi One of my customer is using an eText template for NZ payments and he is getting below error when format payment program is run: java.lang.NumberFormatException: For input string: "null"      at java.lang.NumberFormatException.forInputString(Number

  • Change image size of 42HL800A

    Hi, I am having trouble changing the size of my tv image so that it fills the entire screen. Currently I am watching satellite TV through a set top box that is connected to the 42HL800A. There always seem to be two bars of 'blackness' on either side

  • One of my computers will not from icloud.

    I am using itunes on two windows computers. One of my computers will allow me to download music from  iCloud as will my iPhone but the other will not.