Sound in java

i want to use event sounds & backround sounds
can you help me with that??

Hope this helps some:
java.lang.Object
|
+----symantec.itools.multimedia.SoundPlayer
public class SoundPlayer
implements Serializable
SoundPlayer component. This component allows the playing of a list of sound clips either serially or simultaneously. The sound information is 8-bit 8000hz u-law encoded data.
Index of Public Members
Public Variables
INFINITE
A constant specifying that the sound should run forever.
Public Constructors
SoundPlayer()
Constructs a SoundPlayer.
Public Methods
addPropertyChangeListener(PropertyChangeListener listener)
Adds a listener for all event changes.
addStringURL(String url)
Appends the sound clip data at the specified URL to the current list of sound clips.
addURL(URL u)
Appends the sound clip data at the specified URL to the current list of sound clips.
addVetoableChangeListener(VetoableChangeListener listener)
Adds a vetoable listener for all event changes.
getRepeat()
Gets the number of times the list of sound clips is played.
getSyncMode()
Deprecated.
getURLList()
Gets the URL of each sound clip.
isSyncMode()
Returns the number of times the list of sound clips is played.
play()
Starts playing the sound clips.
removePropertyChangeListener(PropertyChangeListener listener)
Removes a listener for all event changes.
removeVetoableChangeListener(VetoableChangeListener listener)
Removes a vetoable listener for all event changes.
setRepeat(int c)
Sets the number of times the list of sound clips is played.
setSyncMode(boolean newSyncMode)
Sets whether to play the sound clips one after the other, or all simultaneously.
setURLList(URL[] list)
Initializes the list of sound clips using the given list of sound clip data URLs.
stop()
Immediately stops the playing of sound clips.
stop(int delay)
Stops the playing of sound clips after the specified number of milliseconds.

Similar Messages

  • How to Load Sound In Java Application?

    Hi, i dunno what the codes to load sound in java application, can anyone help me and provide me with the codes? Thanks a lot.

    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2Btitle%3Aapplication+%2Btitle%3Asound&col=javaforums
    BTW: You can doo this yourself

  • Sound in Java Program - Tetris

    Hello, I am a student and I just completed my final assignment for my Java class, I was supposed to make a tetris program, im sure you guys have heard of these types of assignments, anyways I would like to add some extra stuff to the assignment, namely, sound, a background song, and a click noise when blocks drop/a line is cleared, I already know how I will implement these things, I just dont know how to work with sound in Java, so if you guys could link to a few tutorials I would really appreciate it, I don't want to use anything outside of the api though so no 3rd party stuff.
    I also am wondering about how to implement some cool things I was thinking about doing, for instance:
    Its been said that there is no way to win tetris because your destined to lose eventually, for that reason most people add a scoreboard to their game so that they can have high scores as a way for making up for not winning, im adding a second element to that, this is something that I already know how to implement, as soon as the game ends, if you are on the high score table, you are presented with a new death match game which is played at the hardest level and if you are able to score half of the points that you scored on the original game you are a winner at which point comes the hard part:
    I was thinking about adding some effects like when you win solitaire in windows and those firework style things go off, except taking that to a new level, I dont know if this is possible, I don't know how to do the fireworks style thing, also I wanted to do it so that the fireworks encompass the whole screen not just the original game screen, for this I was thinking maybe a fully transparent frame that is auto maximized and closes after the animation is done, if anyone could help me with implementing something like this I would really appreciate it.

    if anyone could help me with implementing something like this I would really appreciate it.This forum is conducive for providing help where one asks a specific question about some aspect of Java development. Up to this point, you've described your project and some high-level ideas about it, but you're not clear on what help you need. If it's general end-to-end project assistance, you'd do better to find a helpful peer or start up an open-source project, as this forum is not appropriate for such a thing. If you ho have a specific question or problem, please feel free to ask, but be sure to post the necessary detail for others to help.
    ~

  • How do i play sound in java??

    hello,
    How do i play sound in java??
    im new to java
    thanks,

    There are crude abilities to play sound in the core of java. If you really want to make good sound apps though you should look at the JMF.
    http://java.sun.com/products/java-media/jmf/

  • Sounds in java

    hi all,
    does anybody know how i can add a simple alarm sound in java...something like a beep.
    i need to add a sound to a visual alarm that appears on the screen, but im not sure where
    to start.
    any help or references is greatly appreciated!
    thanks evryone

    Hi
    try applet's play() method with audio clip URL or try using Toolkit.beep() method but its very much system dependent i think.
    hope this helps u
    Shailesh

  • Sound in Java 1.1

    I need to play a sound clip on a Jornada using PJava (which is Java 1.1)
    I found some code but it makes the clip all stuttery and broken up.
    Is there anyway of either
    a) playing a clean sound clip
    b) playing a Tone in Java 1.1 rather than a sound clip
    c) playing sound of some other form ?
    cheers

    With 1.1 you're pretty much stuck with AudioClip. If the device supports it, you could use a MIDI file instead of a sample. Either way, try buffering the sound.

  • How to record sound with Java Sound?

    I just want to record a clip of sound and save it to a WAV file. I exhausted the web but didn't find a tutorial. Would someone be kind enough to give me a tutorial or a sample code? The simpler the better. Thanks.

    Here's the code I used to record and play sound. Hope the length do not confound you.
    import javax.sound.sampled.*;
    import java.io.*;
    // The audio format you want to record/play
    AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED;
    int sampleRate = 44100;
    byte sampleSizeInBits = 16;
    int channels = 2;
    int frameSize = 4;
    int frameRate = 44100;
    boolean bigEndian = false;
    int bytesPerSecond = frameSize * frameRate;
    AudioFormat format = new AudioFormat(encoding, sampleRate, sampleSizeInBits, channels, frameSize, frameRate, bigEndian);
    //TO RECORD:
    //Get the line for recording
    try {
      targetLine = AudioSystem.getTargetDataLine(format);
    catch (LineUnavailableException e) {
      showMessage("Unable to get a recording line");
    // The formula might be a bit hard :)
    float timeQuantum = 0.1F;
    int bufferQuantum = frameSize * (int)(frameRate * timeQuantum);
    float maxTime = 10F;
    int maxQuantums = (int)(maxTime / timeQuantum);
    int bufferCapacity = bufferQuantum * maxQuantums;
    byte[] buffer = new byte[bufferCapacity]; // the array to hold the recorded sound
    int bufferLength = 0;
    //The following has to repeated every time you record a new piece of sound
    targetLine.open(format);
    targetLine.start();
    AudioInputStream in = new AudioInputStream(targetLine);
    bufferLength = 0;
    for (int i = 0; i < maxQuantums; i++) { //record up to bufferQuantum * maxQuantums bytes
      int len = in.read(buffer, bufferQuantum * i, bufferQuantum);
      if (len < bufferQuantum) break; // the recording may be interrupted
      bufferLength += len;
    targetLine.stop();
    targetLine.close();
    //Save the recorded sound into a file
    AudioInputStream stream = AudioSystem.getAudioInputStream(new ByteArrayInputStream(buffer, 0, bufferLength));
    AudioFileFormat.Type fileType = AudioFileFormat.Type.WAVE;
    File file = new File(...); // your file name
    AudioSystem.write(stream, fileType, file);
    //TO PLAY:
    //Get the line for playing
    try {
      sourceLine = AudioSystem.getSourceDataLine(format);
    catch (LineUnavailableException e) {
      showMessage("Unable to get a playback line");
    //The following has to repeated every time you play a new piece of sound
    sourceLine.open(format);
    sourceLine.start();
    int quantums = bufferLength / bufferQuantum;
    for (int i = 0; i < quantums; i++) {
      sourceLine.write(buffer, bufferQuantum * i, bufferQuantum);
    sourceLine.drain(); //Drain the line to make sure all the sound you feed it is played
    sourceLine.stop();
    sourceLine.close();
    //Or, if you want to play a file:
    File audioFile = new File(...);//
    AudioInputStream in = AudioSystem.getAudioInputStream(audioFile);
    sourceDataLine.open(format);
    sourceDataLine.start();
    while(true) {
      if(in.read(buffer,0,bufferQuantum) == -1) break; // read a bit of sound from the file
      sourceDataLine.write(buffer,0,buffer.length); // and play it
    sourceDataLine.drain();
    sourceDataLine.stop();
    sourceDataLine.close();You may also do this to record sound directly into a file:
    targetLine.open(format);
    targetLine.start();
    AudioInputStream in = new AudioInputStream(targetLine);
    AudioFileFormat.Type fileType = AudioFileFormat.Type.WAVE;
    File file = new File(...); // your file name
    new Thread() {public void run() {AudioSystem.write(stream, fileType, file);}}.start(); //Run this in a separate thread
    //When you want to stop recording, run the following: (usually triggered by a button or sth)
    targetLine.stop();
    targetLine.close();Edited by: Maigo on Jun 26, 2008 7:44 AM

  • How to Play a sample sound using Java

    Hi,
    I have an mp3 music files in database. When a user chooses a particular button, all the songs are fetched from the database.
    I have two buttons namely, 'Buy' and 'Play Sample'. If I click the 'Play Sample' button, a sample of the song has to be played (not the full song). If the user likes the sample, he can buy the full song.
    My question is how to achieve the 'Play Sample' using Java Swings and Sound. I have googled, but not find any solutions. Please provide me an example or link.
    Thanks in advance.

    HI
    Actually i am trying to create a JFrame which plays an mp3 music file
    with the help of play and stop buttons in it ...
    i splitted the frame into two
    i want a music file list in the first frame (JComboBox)
    and want to have play and stop button in the second frame .
    i had tried out some code in which the frame part is fine ,,,
    but i am not knowing how to play the file with those buttons ...
    here is the code and plz help me to move further ...
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    public class AudioFile extends JFrame {
        public AudioFile() {
            setTitle("Music File");
            setSize(300, 400);
            JPanel jp1 = new JPanel();
            JPanel jp2 = new JPanel();
            JButton s= new JButton("STOP");
            JButton p= new JButton("PLAY");
            JLabel j1 = new JLabel("MusicFile");
            String[] musicfiles={"file:///home/swathi/Desktop/spot3.mp3","anitha.mp3"};
            JComboBox musiclist=new JComboBox(musicfiles);
            musiclist.setSelectedIndex(1);
            jp1.add(j1);
            jp1.add(musiclist);
            jp2.add(s);
            jp2.add(p);
            JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
                    true, jp1, jp2);
            splitPane.setOneTouchExpandable(true);
            getContentPane().add(splitPane);
        public static void main(String[] args) {
          AudioFile sp = new AudioFile();
            sp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            sp.setVisible(true);
    }

  • Load sound in java application without use of newAudioClip api.

    In personal java 1.2, (JDK1.1.8), the method newAudioClip is unavailable to load sound. What other api can one use to load sound into the java application in this case?

    there's nothing wrong with the old one, except that it's a api of the applet. If you try to run the applet thru' the java app. (without the browser or applet viewer), the getaudioclip api will fail.
    This is the limitation I am facing, 'cos I am developing in Personal Java1.2 env.

  • Importing sound in Java?

    I have a school assignment where I have to programm a synthesizer and I need help with binding a sound to a key. I tried using keyevent but for some reason it won´t work. Any help is appreciated.
    This is the code:
    private void jPanel1KeyPressed(java.awt.event.KeyEvent evt) {                                  
    if (evt.getKeyCode()== KeyEvent.VK_A) {
    URL u = null;
    AudioClip a;
    try{
    u = getClass().getResource("/C.m4a");
    catch (Exception e){
    System.out.println(e.toString());
    a = Applet.newAudioClip(u);
    a.loop();
    }

    first of all, do you really expect Java to support Mpeg4 out of the box? By default only very few audio formats are supported, but you can plugin support for MP3 and OGG for example. Start with wave files and if you can get that to work, I would look into OGG combined with the Java Sound API for your audio needs. AudioClip is just a very limited method of playing a sound, using the Sound API you get all the control you need.
    Secondly, where are you storing your sounds? Using getResource() means that the sound must be in the root of your classpath (meaning it would be in the jar of your applet if you are packaging your application like that). You do not add a slash in front of it, you would call it like this:
    u = getClass().getResource("C.m4a");If you store your sounds in a 'sounds' subdirectory, you would call it like this:
    u = getClass().getResource("sounds/C.m4a");Give some more details about your project if you want more specific help.
    Edited by: gimbal2 on Jan 8, 2009 4:35 PM

  • No sound in java applets in 32bit firefox with bin32-jre plugin.

    I got sound in flash, but not in java applets. Is this a known issue? Any workarounds?

    I should probably make a wiki article (or ad to the Java wiki article) about this, since it seems to come up quite often (especially on Ubuntu forums, actually). The only good solution I've found is to use Pulseaudio, and rename the java executable to java.bin, and make a script called java in the same folder, and put this in the script:
    #!/bin/sh
    padsp /opt/java/jre/bin/java.bin "$@"
    By the way, the path to the java executable is /opt/java/jre/bin/ I've tried using the same method with plain ALSA by using aoss, and it works sorta, but it causes random crashes of Java, so that's a no go, have to use Pulse.

  • No Sound in Java Applets

    I recently installed Arch, switching from Ubuntu,and so far pretty much everything is going as expected.  The one issue I have at the moment is a lack of any sound whatsoever in Java applets.  Sound works in all other contexts, including flash, perfectly.  I am using the sun java implementation, and alsa as my sound server.  Any suggestions as to fixes, or even simply where to look to find fixes, would be greatly appreciated.  A decent bit of searching on my part revealed fixes for similar problems (ie, conflicting sound with other programs) and solutions that were specific to gnome, etc.  Thanks to everyone in advance.

    I should probably make a wiki article (or ad to the Java wiki article) about this, since it seems to come up quite often (especially on Ubuntu forums, actually). The only good solution I've found is to use Pulseaudio, and rename the java executable to java.bin, and make a script called java in the same folder, and put this in the script:
    #!/bin/sh
    padsp /opt/java/jre/bin/java.bin "$@"
    By the way, the path to the java executable is /opt/java/jre/bin/ I've tried using the same method with plain ALSA by using aoss, and it works sorta, but it causes random crashes of Java, so that's a no go, have to use Pulse.

  • Using sound with Java

    Is there any way to generate sound from special files (ie , format that I created myself) instead of from supported files (ie, wave) ? i mean generate sound from RAW data. because I create sound from MATLAB and store it in my format and I want it to be playted using Java.
    Best Regards
    Theeraputh Mekathikom

    Is there any way to generate sound from special files
    (ie , format that I created myself) instead of from
    supported files (ie, wave) ? i mean generate sound
    from RAW data. because I create sound from MATLAB and
    store it in my format and I want it to be playted
    using Java.
    Best Regards
    Theeraputh MekathikomThe wave format is really simple. It's practically raw data (some metadata added). I think that probably it will be easier to create a wave file with matlab than working with a propritary format on Java. Just to some google search on waves.
    Hope this helps

  • I need some help with sound in Java

    hi, i`m new to java. i`m having a through problems with a program i`m writing. i`ve added a song to an applet but it does not play. The code for this is:
    private AudioClip music;
    music = getAudioClip(
    getDocumentBase(), "titantic.wav" );
    Can some 1 tell me is that the write code. please help.

    2 things.
    1. You must also send a command to play the music file.
    2. I'm not certain, but I think that you can only load .au files this way.

  • Generating sound in Java

    Hi all!
    I'm about to build a Java class that can generate raw audio data. My intention is to write a java calss that given two frequencies starts generating a stream of 16-bit signed values generated by the function f(freq1,freq1). My first question is: Has someone an idea of how this could be done. Has it been done before?
    The tones I want to generate is DTMF tones and I have written the skeleton of the class including the function f(freq1, freq2). My problem is how to get the bit values from the samples and how to make sure that they are 16 -bit signed. Can someone help me with some tips?
    Thanks in advance!
    Regards,
    Andreas

    Thanks Djamal!
    I have some problems getting my Bytearray. The function is as follows:
    F(freq1, freq2) = (sin(2*PI*freq1*t) + sin(2*PI*freq2*t))/2
    When Ido some testing I only get 1,0 or -1. I don't know if this is an question that has to do when trying to print the result, is it possible to print a short value as it is in bits? I will try with your example.
    Maybe you see something that is wrong in my code? The datatypes are:
    2*PI*freqN is float,
    t is float
    and I want to cast this so that F(freq1,freq2) returns a short. Could I loose some information in that cast? Any suggesstions?
    Again, thank you very much for your help!
    regards,
    Andreas

Maybe you are looking for