Results 1 to 3 of 3
  1. #1
    peiceonly is offline Member
    Join Date
    Mar 2007
    Posts
    41
    Rep Power
    0

    Default Applets having sound

    Hi all
    How can we include sounds inside in an applet?

    thanks peiceonly

  2. #2
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    Hi peiceonly

    Playing audio clips in applets is quite simple and involves the following steps:

    * Create AudioClip object
    * Load .au sound file into AudioClip
    * Play sounds once or many within a loop

    code is shown below

    Java Code:
    import java.applet.*;
    AudioClip ac = getAudioClip(getCodeBase(), soundFile);
    ac.play();   //play once
    ac.stop();   //stop playing
    ac.loop();   //play continuously

  3. #3
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    Hi
    By the way it wont work for other application other than applets then use
    Java Code:
    import  sun.audio.*;    //import the sun.audio package
    import  java.io.*;
    //** add this into your application code as appropriate
    // Open an input stream  to the audio file.
    InputStream in = new FileInputStream(Filename);
    // Create an AudioStream object from the input stream.
    AudioStream as = new AudioStream(in);         
    // Use the static class member "player" from class AudioPlayer to play
    // clip.
    AudioPlayer.player.start(as);            
    // Similarly, to stop the audio.
    AudioPlayer.player.stop(as);

Similar Threads

  1. add sound to my applet
    By anotsu in forum Java Applets
    Replies: 4
    Last Post: 03-25-2008, 12:26 AM
  2. Re-playing sound
    By JSK in forum CLDC and MIDP
    Replies: 0
    Last Post: 02-06-2008, 12:34 PM
  3. Converting a byte[] into Sound
    By savage82 in forum Advanced Java
    Replies: 1
    Last Post: 11-22-2007, 12:57 AM
  4. applet sound
    By marco in forum Java Applets
    Replies: 1
    Last Post: 09-28-2007, 11:31 PM
  5. Sound in applet Java
    By toby in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 06:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •