Basic Sound Class

I'm am busy creating a simple game. I want the user to be able to play wav files while the game is running. Could someone possible point me to a very basic Class that plays wav files. Basically i want to be able to create a new instance of this class and send it the filename, and it must then play the file. Try as i might, JavaSound just confuses me.
thanks.

have you seen this?
[url http://www.jsresources.org/examples/SimpleAudioPlayer.java.html]sample
sourcecode sample / demo

Similar Messages

  • Encountering Problems with Basic Sound Tutorial

    Hello everyone,
    I am encountering problems with a basic sound tutorial. I am absolutely confused as to what the problem may be because the code is so simple, and is essentially copied from the textbook. I am convinced that I have done something very silly but cannot see it.
    I have attempted to run this in an appletviewer, Firefox and Internet Explorer. I have attempted to launch it from both a .class file and a .jar file. I have uninstalled and offline installed the JDK and JRE and successfully tested the new installations.
    The audio file I am attempting to load and play is an .AU (Sun/Next 8-bit u-law) audio file I created in Audacity. It is located in the same folder as the AudioApplet.class file.
    My sound system is defintely on, since I have listened to music all day. I have attempted running the program with Media Player closed.
    package edu.myuniversityid.sandbox;
    import java.applet.Applet;
    import java.applet.AudioClip;
    * @author Ibuki
    public class AudioApplet extends Applet
         * Initialization method that will be called after the applet is loaded
         * into the browser.
        public void init()
            super.init();
            AudioClip ac = this.getAudioClip(this.getDocumentBase(), "sample.au");
            ac.play();
    }The code compiles fine, however absolutely I get a small white window when it is run. No sound.
    Thankyou for your time.
    Regards,
    Ibuki.
    PS. I am sure this worked before the university forced me to update my version of Windows to SP2. Hence, the reason for reinstalling Java. Twice.
    Edited by: Ibuki on Jan 31, 2008 11:09 AM becasuse: Added a PS.

    I have attempted this alternative, without success:
        public void init()
            try
                super.init();
                URL url = new URL(this.getDocumentBase(), "sample.au");
                AudioClip ac = this.getAudioClip(url);
                ac.play();
            catch (MalformedURLException ex)
                Logger.getLogger(AudioApplet.class.getName()).log(Level.SEVERE, null, ex);
        }The sample.au is definetly in the correct directory. Both File Explorer and NetBeans confirm this.
    Edited by: Ibuki on Jan 31, 2008 11:59 AM
    I have discovered a temporary solution that works in the applet viewer. The applet will load and plays the correct music perfectly. However, using this code it is not working when I try to deploy it using a web browser (MSIE and FF)!
    public void init()
            super.init();
            AudioClip ac = this.getAudioClip(this.getClass().getResource("sample.au"));
            ac.play();
    Edited by: Ibuki on Jan 31, 2008 12:12 PM
    Eureka!
    Having worked in the applet viewer I managed to get it working in the web browser by simply packaging my SoundApplet.class and sample.au into a .jar archive.
    <html>
         <body>
              <applet code="edu.myuniversityid.sandbox.AudioApplet.class" archive="dist/AudioApplet.jar">Unfortunately, this applet content cannot be displayed on this web page because your current browser does not support Java SE 6! Please <a href="http://www.java.com/">update your version of Java</a>.</applet>
         </body>
    </html>
    public void init()
            super.init();
            AudioClip ac = this.getAudioClip(this.getClass().getResource("sample.au"));
            ac.play();
        }Thankyou everyone.
    This thread can be closed if applicable. I'm not aware of the current moderation policy on this forum.
    Edited by: Ibuki on Jan 31, 2008 12:12 PM

  • Looking for information about AS3 sound classes in "audio" wrong places?

    I'm looking for in depth information about ActionScript 3.0 sound classes. No matter where I search I continually encounter the same sort of kindergarten level descriptions, which never teach more than what we can readily glean from Adobe's documentation. Someone must know where there a discussion that really gets to the heart of the matter.
    I've read Adobe's LiveDocs on the Sound, SoundChannel, SoundMixer, SoundTransform classes. Indeed, they provided me enough guidance to create my own streaming MP3 player, with volume, pan, my own custom mono mix, http request, a preloading animation, and peak meters ...
    Here's an example (in the last statement of the following code) where I understand the end effect, but I fail to comprehend what happens at the compiler level:
    var currentSoundSource:Sound = new Sound();
    currentSoundSource.load(new URLRequest("http://www.mySite.com/myRecording.mp3"));
    var audioChannel_01:SoundChannel = new SoundChannel();
    audioChannel_01 = currentSoundSource.play();
    Unfortunately the class definitions in LiveDocs are quite terse, and they're seemingly incomplete with respect to:
         •     advice on best practices
         •     a thorough coverage of class to class interactivity
         •     a description of exactly how audio streams/plays into channels
    ... and in certain cases it appears that Adobe's descriptions are not fully accurate.*
    Regarding best practices, at first blush I'm sure everyone ponders over the fact that SoundChannel and SoundMixer have a stop method while the Sound class does not.
    One assumes that this surprising design must bear some advantages. If so,  what are they? Where are the analog sound mixer analogies? What would be the disadvantage of a sound class with a stop method ...  particularly when they have their own play method?
    Where are the discussion of these concepts? (Even if Adobe hired the wrong guy to write its sound classes, there should be some follow through that thoroughly explains the existing situation.)
    Phrankie
    * Here's an instance where the docs appear to be partially in error. (Is "and play" mistakenly included in the following?)
    "The Sound class lets you lets you create a new Sound object [and] load and play an external MP3 file into that object."
    ... uh, mmmmmm ... we play an MP3 into a sound class object?
    Wouldn't it be more accurate to say the following:
    A soundChannel can receive the audio data from a sound class object. We can play a sound object into an SoundChannel and manipulate it by altering the SoundChannel's soundTransform property, and we can stop it with the SoundChannel's stop method. 

    check everything you can find written by tinic uro.  this will get you started:  http://www.kaourantin.net/

  • About playing dynamic generated sound using Sound class

    Dear sir:
    The live doc of Flex 4 says:
    In Flash Player 10 and later and AIR 1.5 and later, you can also use this    class to work with sound that is generated dynamically.    In this case, the Sound object uses the function you assign to a sampleData event handler to   poll for sound data. The sound is played as it is retrieved from a ByteArray object that   you populate with sound data.
    and i read one article(the following link)
    http://www.kaourantin.net/2008/05/adobe-is-making-some-noise-part-2.html
    it said: The Sound class only support 44100 sample rate,32 bit,2 channel sound data, is that true?
    Then if i get one ByteArray( 8000 sample rate,16bit,1 channel), how can i modify it to let the Sound class play it?
    thanks..

    Worked perfectly.  Thank you thank you!
    Jen

  • Basic Java Class with prints records out of the DEPT table

    Can some one show a basic java class which will query the DEPT table, and print them out?

    Nagarjuna,
    the Oracle DBMS JDBC Developer's Guide is full of code examples.
    http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/toc.htm
    --olaf                                                                                                                                                                                                                                                                                                                       

  • Sound class

    Hi everyone. I'm creating an audio player which will receive
    xml information from a server and play the requested sone. I have
    all that set up. The only problem I'm having with is creating the
    progress bar while the sound is streaming. What happens is when the
    audio player is opened, the song starts playing because of the
    streaming property that I set in the actionscript, but the progress
    bar doesn't show up until the song is fully cached on the user's
    machine. So the effect is you don't see the progress bar when the
    audio player opens and the song plays. Instead the progress bar
    will appear a couple of seconds after the audio player starts
    playing. I've put the project up on my site, so you can take a look
    at it and see what I'm talking about,
    www.mark-yieh.com/airspun/newaudioplayer.html. If you know how to
    fix it please let me know. It will really be appreciated. Thanks.
    I've looked at all the event handlers in the sound class, but none
    of them let's me gather information from the sound file until it's
    fully loaded. For example, with the MovieClipLoader class, there's
    an onLoadInit handler and an onLoadStart handler and an
    onLoadProgress handler, but there's none for the sound class. Is
    there another solution?

    if you're attempting to get the sound.duration before it has
    loaded, then you'll find that this will only return the number of
    seconds downloaded so far. sound.position should work okay though.
    check out the comments in
    livedocs
    for sound duration for some handy ways to approximate this
    property during streaming.

  • Sound class pause

    Hi i have a flash presentation, which has a pause and play
    button.
    the pause button pauses my movie fine, except i have voice
    sound as a sound class, the sound starts to play, but i can not get
    it to pause or stop
    any ideas what i need to do?
    i have the following code

    no, your code above is not correct: your onRelease functions
    are written as such to be placed directly on your button objects
    and not on the root time line; additionally, the function
    volAdjust(), which is the function responsible for controlling your
    sound, is not present in your code at all.
    to fully understand what is going on, take five minutes to do
    this:
    1.) open a brand new flash document.
    2.) import a sound to your library ( file > import >
    import to library ), open your
    library ( f11), right-click on the sound inside your library
    and select linkage,
    check export for actionscript, make sure export in first
    frame is checked, and
    then enter, newWelcome , into the identifier text field.
    3.) draw a rectangle on stage and convert it to a movieclip
    (f8) - name it whatever you wish.
    4.) with the newly created movieclip selected, go to your
    properties inspector
    and enter the string, btnPlay , into the instance name text
    field.
    5.) open your library ( f11) and drag another instance of the
    movieclip you just
    created onto the stage.
    6.) with the newly dragged out instance of your movieclip
    selected, go to your
    properties inspector and enter the string, btnPause , into
    the instance name text field.
    7.) make a new layer above the one you have working in and
    name it actions.
    8.) lastly ,copy and paste the code i sent you into the first
    frame of the layer
    actions. (note: your movieclips, btnPlay and btnPause,
    should be on the first
    frame of your second layer ( the layer beneath your layer
    labeled actions ).

  • Why Sound Class is greyed out?

    Hi, there
    I am trying to assign a sound class, but found it was greyed out. I'd appreciate if someone could help me to find a way...Thanks!

    I think you're right. The file I was working on was originally in AS2...Thanks a lot!

  • Sound class help?(oop)

    hey,
    i have got all my public vars for sound class but im having trouble on how i would execute them because i normal would use event listener but its OOP lol so how do you get that functionality :/
    ---code in star.as file:
    package
        import flash.display.MovieClip;
        public class star extends MovieClip
            public var my_sound:MySong = new MySong();
            public var my_channel:SoundChannel = new SoundChannel();
            public function star()
    thanks everyone

    dont worry i learnt oop and made my own class here it is if anyone has the same problem!
    Code:
    package
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.media.Sound;
        public class SoundClass extends MovieClip
            var sound = new Sound  ;
            var mySound:MySong = new MySong  ;
            public function SoundClass()
                mySound.play();
    Hope this helped somebody else

  • Framewrok extension: Basic EntityImpl class

    Hi,
    JDev 10.1.3.0.4
    I have written a basic EntiyImpl class that trims leading and trailing blanks of String attributes, inspired from the Struts ADF Basic Entity class.
    So to implement that basic entity class: BasicEntityImpl in an Entity based on a table, let's say AddressImpl, I replaced:
    public class AddressImpl extends EntityImpl
    by
    public class AddressImpl extends BasicEntityImpl
    But everytime I exit the Entity editor with Apply or OK, the editor writes the original extension:
    public class AddressImpl extends EntityImpl
    How can I avoid that?
    and why can't I choose my BasicEntityImpl class in the field Extends Entity in the editor?
    BasicEntityImpl is part of a specific package in my model project and I doesn't display when use the browse button.
    Thanks
    Fred

    I would like to add that not all entities must extend that Basic Entity class.
    So I can't configure it at a project level.
    Regards
    Fred

  • Automatically generated (Sound) classes

    Hi all,
    Quick summary:
    I'm trying to compile a SWC file with a lot of assets in it in an as easy possible way. "Easy" for a not so technical end user, not perse the way to acchieve that goal. Goal is to streamline a process to generate SWC files with as little possible tech for the person doing it.
    So, sort of like  manually doing:
    * Import files into Flash
    * For each library item select "Export for actionscript" and have Flash generate the basic class.
    * Publish as SWC
    but without the Flash IDE and the possibly labourous process.
    Right now I'm trying to put an AIR project together that generates classes based on a file list. The classes can than be added to a Flash Builder library project to generate a SWC file from it (copy in finder, check classes in Project properties, done)
    I can generate the classes for graphics like below. Such a class can then be instantiated from within the host application.
    package
              import flash.display.Bitmap;
              import flash.display.MovieClip;
              public class __0038_asset extends MovieClip
                        [Embed(source="assets/__0038_asset.png")]
                            private static const gfx:Class;
                        public function __0038_asset()
                                  super();
                                  addChild( new gfx() as Bitmap );
    Allthough this adds another level to the display list (which looks kinda sloppy to me), it works.
    However, for this to work for sound files I need to create a class implementing all possible methods and properties of the soundclass and handle the events and such. There is no way to extend Sound and then do something like you would/can with graphics.
    This is what I got:
    package
              import flash.media.Sound;
              import flash.media.SoundLoaderContext;
              import flash.net.URLRequest;
              public class _000_cover_hotsp_authormp3 extends Sound
                        [Embed(source="assets/000_cover_hotsp_author.mp3")]
                        private var snd:Class;
                        public function _000_cover_hotsp_authormp3(stream:URLRequest=null, context:SoundLoaderContext=null)
                                  super(stream, context);
                                  var mySound:Sound = new snd() as Sound;
    But that aint gonna work ofcourse.
    Does anyone know if there is a way to get to the format the Flash IDE generates the classes with?
    Thanks in advance.
    Manno

    Wel, here's the answer. Must have read it once since it is in the moock book, but stubled across it on the interwebs at: http://blog.nightspade.com/2010/02/01/embedding-asset-at-compile-time-in-pure-as3-project/
    For images use:
            [Embed(source="assets/Frog&Stranger02_03-titelblad_height_1024px 2.jpg")]
              public class a_A2BA79B5_CE46_F942_1AB2_CC26D8F7FCC8 extends Bitmap
                        public function a_A2BA79B5_CE46_F942_1AB2_CC26D8F7FCC8()
                                  super();
    and for sounds:
              [Embed(source="assets/000_cover_hotsp_author.mp3")]
              public class _000_cover_hotsp_authormp3 extends Sound
                        public function _000_cover_hotsp_authormp3()
    Now, lets review some code to see if I can apply this elsewhere too

  • Performance problems with external sounds and Sound class

    I'm using Sound & SoundChannel classes to load and play external MP3s and I'm seeing terrible playback performance on my 3G phone. Audio starts out ok, but will gradually get more and more choppy and eventually crashes the app. The MP3s themselves are typical sizes, 2 - 6 MB and of various types (VBR, CBR).
    On top of that, when the phone gets locked (with the app still running), the audio sputters and stops completely. When I unlock, it begins where it left off. Anyone else seeing this?
    My code is pretty standard:
    private var soundPlayer:Sound;
    private var soundChannel:SoundChannel;
    public function load(url:String, playNow:Boolean = true):void {
      if (soundChannel) {
        soundChannel.stop();
      soundPlayer = new Sound();
      soundPlayer.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
      soundPlayer.addEventListener(ProgressEvent.PROGRESS, onProgress);
      soundPlayer.addEventListener(Event.ID3, onID3);
      trace('Loading new stream: '+url);
      var request:URLRequest = new URLRequest(url);
      soundPlayer.load(request);
      if (playNow) {
        this.isPlaying = true;
        soundChannel = soundPlayer.play();
        soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);

    this is from another forum (http://discussions.info.apple.com/thread.jspa?threadID=2542931&tstart=0&messageID=12106188 ):
    "I've spoken to the developers of of couple of these apps, and they've all said it's a memory fragmentation/low memory condition.
    Restart the phone. Don't just turn it off and on, but restart it.
    Hold the on/off button and the home button down like you were going to turn it off. When you see the swipe to turn off message, keep holding the buttons down.
    In a few seconds the screen will flash, and then go dark.
    Now it's really off.
    Turn it back on (restarting it). All should be well.
    The iPhone is really a computer. Performing a restart like this every  once in a while (weekly, bi-weekly) is a good idea, esp if you use  memory intensive apps."
    coop

  • Should I use Borlands Basic Wizard class?

    Hi,
    I am just about to start programming a wizard for my Swing application. I am using Borland JBuilder as an IDE and in the help file found a class called "Basic Wizard". Is this not an official class? If the answer is yes, is it advisable to use this class, and other 3rd party classes.
    cheers
    David

    hm I do not know the JBuilder (like seen once, deinstalled and stayed on Forte4Java g) but it seems like the "Basic Wizard" is just one other "Borland specific" Class in it�s own IDE.
    I did never see this class anywhere in Java 1.4.x and so it seems, its one of Borland�s own things, and there�s one way:
    "Use at own risk..."

  • Could you please suggest me the basic ABAP class names?

    I am trying to go to ABAP training, so l like to know the basic class name that i can take to learn ABAP. Please let me know. Thank you in advance.
    Aslam.

    Fundamentals is good, but you will also need these to really get you going.
    ABAP Objects
    http://www50.sap.com/useducation/curriculum/course.asp?rid=466&cid=60187182
    Advanced ABAP
    http://www50.sap.com/useducation/curriculum/course.asp?rid=466&cid=60208381
    Programming ABAP Reports
    http://www50.sap.com/useducation/curriculum/course.asp?rid=466&cid=60193497
    ABAP Dictionary
    http://www50.sap.com/useducation/curriculum/course.asp?rid=466&cid=60173823
    Regards,
    Rich Heilman

  • Compilation Error in basic java class

    Hello,
    I am newbie. And, I have developed following java classes. But the child class is results in error. Below is step by step event. What am I doing wrong?
    Step 1. Created a compiled class Shirt(parent). No issues
    public class Shirt {
    public int shirtID =0;
    public String description = "description required";
    // color codes
    public char colorCode = 'U';
    public double price = 0.0;
    public int quantityInStock = 0;
    // methods
    public void displayShirtInformation() {
       System.out.println("Shirt ID: " + shirtID);
       System.out.println("Shirt description:" + description);
       System.out.println("Color Code:" + colorCode);
       System.out.println("Shirt price: " + price);
       System.out.println("Quantity in Stock :" + quantityInStock);
    } // end of method
    } // end of class
    Step 2. Child class results in compilation error
    public class ShirtTest{
    public static void main (String[] args) {
         Shirt myShirt;
         myShirt = new Shirt();
         myShirt.displayShirtInformation();
    Step 3. Error show below
    C:Java>javac ShirtTest.java
    ShirtTest.java:4: cannot find symbol
    symbol  : class Shirt
    location: class ShirtTest
         Shirt myShirt;
         ^
    ShirtTest.java:5: cannot find symbol
    symbol  : class myShirt
    location: class ShirtTest
         myShirt = new myShirt();
                       ^
    2 errors Thanks D,

    Hello all. I am in a similar boat as far as getting the error message:
    javac ShirtTest.java
    ShirtTest.java:7: cannot find symbol
    symbol  : class Shirt
    location: class shirt.ShirtTest
            Shirt privShirt = new Shirt();
            ^
    ShirtTest.java:7: cannot find symbol
    symbol  : class Shirt
    location: class shirt.ShirtTest
            Shirt privShirt = new Shirt();
                                  ^
    2 errorsMy Shirt.java is as follows(which compiles just fine):
         1  package shirt;
         2
         3  public class Shirt {
         4
         5      private char colorCode = 'U';
         6
         7      public char getColorCode() {
         8          return colorCode;
         9      }
        10
        11      public void setColorCode (char newCode) {
        12          colorCode = newCode;
        13      }
        14
        15  }And my ShirtTest.java is as follows:
         1  package shirt;
         2
         3  public class ShirtTest {
         4
         5      public static void main (String args[]) {
         6
         7      Shirt privShirt = new Shirt();
         8      char colorCode;
         9
        10      privShirt.setColorCode('R');
        11      colorCode = privShirt.getColorCode();
        12
        13      System.out.println("Color Code: " + colorCode);
        14      System.out.println(" ");
        15
        16      privShirt.setColorCode('Z');
        17      colorCode = privShirt.getColorCode();
        18
        19      System.out.println("Color Code: " + colorCode);
        20
        21      }
        22
        23  }This is basically from the Fundamentals of the Java ^TM^ Programming Language SL-110-SE6 Student Guide(pages 9-12 & 9-13). We are working on Encapsulation if that makes any difference. Maybe it's just me but this book is not very new programmer/user friendly. At least in my opinion. I find it very frustrating that I can't even type in examples from the book and get them to work.
    I have tried the javac -cp . ShirtTest.java suggested here but get the same error. I have removed all *.class* files and still no luck.
    OS:
    uname -a
    SunOS 5.10
    JAVA:
    java -version
    java version "1.5.0_26"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_26-b03)
    Java HotSpot(TM) Server VM (build 1.5.0_26-b03, mixed mode)
    Anyway, any help would be appreciated.

Maybe you are looking for

  • How to split Value in a field while importing

    Hi, I want to split Value in Field and map it 2 target Field. Suppose Street field having values with House number and street name ,need to split  at House Number and street name and map it 2 fields EX : 1123 Dhuram Ave:    Need to split 1123 and Dhu

  • Please help - Toplink on Websphere5.1

    Hi, I am newbie on Toplink and I am trying to use toplink to run on a sample table with EJB 2.0 CMP and Session Facade. I created a project.xml and toplink-ejb-jar.xml(renamed the session.xml for Websphere) using toplink workbench and placed in the M

  • How do I search a site using radio buttons

    I am trying to search a site using radio buttons. I have one table and 5 columns. I have 5 radio buttons marked like 01, 02, 03,04,05. I am using Dreamweaver cs5 php, when I click the radio button 01 I will like to get the response with all 01 files.

  • Material - Vendor relation in QN

    Hi, We have requirement for Notification. At the time of creation of manual Notification (T-code: QM01). Once we enter Material & if this material is ROH then system should go in source list (t-code: ME03) to select available vendor of material. If m

  • How do I auto set stroke weight, stroke colors & fill color?

    Hi, I'd like to make it easier for our 100,000 designers to use AI to make custom products using a laser cutter. Current Practice Designers open our AI laser cutting design templates, add their designs using the AI settings our online pricing system