Play sound in a java application

Hi,
I am creating a sound player program in a java application. Is that possible ? If yes, please tell me how to do that.
Please reply soon!
Thank you!

i have had to use javax.sound and also Java Media Framework to do an aplication, and think jmf is easier than javax.sound cause things in jmf are more abstracted than in js. try with jmf

Similar Messages

  • Playing sounds in a Java Application?

    Hi,
    I am making a simple chat program, and want to include sounds for sending a receiving messages, but I can't seem to get it to work.
    First, does anybody have an easy solution to just Load 2 clips of aduio, and play them on-command? So when I send a message, I can just play the audio file once with a simple line of code?
    If so, that is way easier than the way I am currently trying :P
    Regards,
    -Josh

    MIDI is very easy to play in your applications. WAV might be a bit trickier.
    For some slightly advanced midi playback, check out this link:
    http://javaalmanac.com/egs/javax.sound.midi/pkg.html
    For basic MIDI playback,
    See "Playing Sounds from an Application" in this article:
    http://java.sun.com/docs/books/tutorial/sound/playing.html
    Or see:
    http://www.javaworld.com/javaworld/javatips/jw-javatip24.html
    As for WAV, maybe this? I've never used WAV.
    http://www.rgagnon.com/javadetails/java-0191.html

  • JMStudio locks up playing sound file - using java 1.5.0_02 - HELP!

    I'm using the jmf 2.1.1e cross platform version on Windows XP SP2. I have java 1.5.0_02 installed.
    When I open the sound file using JMStudio it locks up. It plays videos that don't have sound fine, so it's not the video. It's the sound that is killing it.
    Does anyone have any suggestions?

    Hi,
    yeah it's possible to play sound on Windows but you have to use the Windows Performance Pack instead of the crossplatform-version of JMF.
    This has to do with the JavaSound Architecture of Java 5.0. They made changes and now the JavaSound Renderer didn't work under Windows but the DircetSound Renderer works fine.
    So be sure that your application uses the DirectSound Renderer!
    This is one of the main problems of JMF but now Sun gets interested in JMF and they would build a new version of JMF. If this is true they have to fix this problem!
    Best regards, thomas

  • Please.. need help!! Problem with playing sounds

    Hello, any help at all greatly appreciated.
    I need a dead-certain way of playing sounds with my java application.
    Java media player doesn't seem to be working with sound files with a duration of longer than 30 seconds.
    I need a way of accessing the windows sound API from inside my java app.
    Anyone have any ideas??????

    Hello, any help at all greatly appreciated.
    I need a dead-certain way of playing sounds with my java application.
    Java media player doesn't seem to be working with sound files with a duration of longer than 30 seconds.
    I need a way of accessing the windows sound API from inside my java app.
    Anyone have any ideas??????

  • Help with playing sound in applications

    im new to java and i was practicing playing sound in a swing application but the problem is that when i press the play button no sound is played...here is my code
    import javax.swing.*;
    import java.applet.AudioClip;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.io.File;
    public class JukeBox extends JFrame {
        private JLabel label;
        private JPanel panel, buttonPanel;
        private JComboBox playList;
        private JButton play, stop;
        private URL url1, url2, url3, url4, url5, url6;
        private AudioClip[] musicList;
        private AudioClip current ;
        public JukeBox() {
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(500, 120);
            setLocation(50, 50);
            setTitle("JAVA JukeBox");
            url1 = url2 = url3 = url4 = url5 = url6 = null;
            current = null;
            try {
                url1 = new URL("file", "localhost", "C:\\Documents and Settings\\KADA\\IdeaProjects\\Sound\\bottle-open.wav");
                url2 = new URL("file", "localhost", "C:\\Documents and Settings\\KADA\\IdeaProjects\\Sound\\BP2.mp3");
                url3 = new URL("file", "localhost", "C:\\Documents and Settings\\KADA\\IdeaProjects\\Sound\\fhm.aiff");
                url4 = new URL("file", "localhost", "C:\\Documents and Settings\\KADA\\IdeaProjects\\Sound\\jungle.rmf");
                url5 = new URL("file", "localhost", "C:\\Documents and Settings\\KADA\\IdeaProjects\\Sound\\spacemusic.au");
                url6 = new URL("file", "localhost", "C:\\Documents and Settings\\KADA\\IdeaProjects\\Sound\\trippygaia.mid");
            } catch (MalformedURLException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            musicList = new AudioClip[7];
            musicList[0] = null;
            musicList[1] = JApplet.newAudioClip(url1);
            musicList[2] = JApplet.newAudioClip(url2);
            musicList[3] = JApplet.newAudioClip(url3);
            musicList[4] = JApplet.newAudioClip(url4);
            musicList[5] = JApplet.newAudioClip(url5);
            musicList[6] = JApplet.newAudioClip(url6);
            label = new JLabel("JAVA JukeBox", JLabel.CENTER);
            String[] musicList = {"select a track..."
                    , "bottle open"
                    , "bitch please II"
                    , "flutte, harmonica, mambo"
                    , "jungle"
                    , "spacemusic"
                    , "trippygaia"};
            playList = new JComboBox(musicList);
            playList.addActionListener(new ListListener());
            play = new JButton("Play");
            play.setActionCommand("play");
            play.addActionListener(new ButtonListener());
            stop = new JButton("Stop");
            stop.addActionListener(new ButtonListener());
            buttonPanel = new JPanel();
            buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
            buttonPanel.add(play);
            buttonPanel.add(stop);
            panel = new JPanel();
            panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
            panel.add(label);
            panel.add(Box.createRigidArea(new Dimension(0, 5)));
            panel.add(playList);
            panel.add(Box.createRigidArea(new Dimension(0, 5)));
            panel.add(buttonPanel);
            getContentPane().add(panel);
        private class ButtonListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                if(current != null){
                    current.stop();
                if(e.getActionCommand().equalsIgnoreCase("play")){
                    if(current != null){
                        current.play();
        private class ListListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                if (current != null) {
                    current.stop();
                current = musicList[playList.getSelectedIndex()];
        public static void main(String[] args) {
            setDefaultLookAndFeelDecorated(true);
            JukeBox jb = new JukeBox();
            jb.setVisible(true);
            jb.setResizable(false);
    }can u please tell me whats wrong with my code coz i cant hear no sound when i press the play button and can u please tell me why i cant simply put the file name in the URL instead of the complete path although the files are in the same directory of the source code and can i play mp3 using this little program ???
    plz help...im a newbie so plz explain as much as u can...

    After
    musicList = new AudioClip[7];
            musicList[0] = null;
            musicList[1] = JApplet.newAudioClip(url1);
            musicList[2] = JApplet.newAudioClip(url2);
            musicList[3] = JApplet.newAudioClip(url3);
            musicList[4] = JApplet.newAudioClip(url4);
            musicList[5] = JApplet.newAudioClip(url5);
            musicList[6] = JApplet.newAudioClip(url6);initialise the variable current with
    current = musicList[1];or similar because the AudioClip current always == null in your code so your listener blocks don`t execute.
    regards

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

  • How to play sounds on Frames

    I'm been working with sounds on applets and is pretty easy play sounds and build funny stuff.
    But now i need to play sounds on a Frame (Application) and i realize that sounds can be load only on applets(so far thats what i know)
    If anyone knows how play sounds without an applet please let me know this is a huge issue for me.
    thanks in advance.
    Andrey

    See the following thread for a sample program:
    http://forum.java.sun.com/thread.jsp?forum=54&thread=97984

  • Sound volume in java games on E70

    Hi,
    How to change sound volume in java applications?
    The sound is too loud
    Cheers,

    Yes I have this problem with the N80.
    why oh why Nokia deciced to remove the side volume I have no idea. In a call you have to say "hold on" to the person on the line to change the volume.
    If Nokia are going to justify removing things like this then they need to also come up with a flawless alternative. I can only play games with the music on or off.
    Can anyone from Nokia monitoring this thread find out for us why it was removed? and if it was to save space then why doesnt it work all the time?
    Even making it so other keys could turn it up and down wasnt even added!
    Whats going on guys? this is standard usability.Message Edited by stevehodges on 27-Oct-2006
    09:35 PM
    Current Nokia: N80 Black! & 6300 Black!, Next nokia: N96 Previous Nokias: 6230i, 8310,8210,7210,6210,6110,6100,3310 and 2110!
    If I worked for Nokia, I would try and make things work correctly! ;-)

  • Playing a Sound clip in a Java Application

    Ive searched a bunch on google to find a way to play an audio file in java, ive found how to do this in an applet but this is not what i want, I need to get it to work in a normal java application, any help would be appreciated.

    The methods that load an audio clip for you in the Applet class are static methods; iow you don't need an Applet at all, just use the (utility) methods in that class. Granted, these methods deserve a better, more neutral place.
    kind regards,
    Jos

  • Only one application is able to play sound at a time.

    I installed arch on my desktop a couple weeks ago (finally 100% windows free ), but I've been having the hardest time getting audio working flawlessly.
    At first I was having problems using the correct sound card as default, but It seems I have that working now. I can get sound to play, but only 1 application can access the sound card at the same time. If I have spotify playing and I try to play a youtube video in browser, the video will play for a few seconds with no sound and then completely crash. If I pause spotify and refresh the youtube page, the video will play. And also, while a youtube video or anything else is playing, any other application will refuse to play sound.
    I guess this is an issue with ALSA. My sound card seems to be blocking other sources.
    If I run speaker-test while something is playing I get this output:
    speaker-test 1.0.27.2
    Playback device is default
    Stream parameters are 48000Hz, S16_LE, 1 channels
    Using 16 octaves of pink noise
    Playback open error: -16,Device or resource busy
    And for possible helpful information, here is the output of aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: PCH [HDA Intel PCH], device 0: ALC892 Analog [ALC892 Analog]
    Subdevices: 0/1
    Subdevice #0: subdevice #0
    card 0: PCH [HDA Intel PCH], device 1: ALC892 Digital [ALC892 Digital]
    Subdevices: 1/1
    Subdevice #0: subdevice #0
    card 1: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
    Subdevices: 1/1
    Subdevice #0: subdevice #0
    card 1: NVidia [HDA NVidia], device 7: HDMI 0 [HDMI 0]
    Subdevices: 1/1
    Subdevice #0: subdevice #0
    card 1: NVidia [HDA NVidia], device 8: HDMI 0 [HDMI 0]
    Subdevices: 1/1
    Also, this is what I have put in /etc/asound.conf in order to get my sound card to load as default (just in case I've done something wrong here):
    pcm.!default {
    type hw
    card PCH
    ctl.!default {
    type hw
    card PCH
    So what am I missing here?
    Last edited by tylerpnn (2014-03-29 04:54:00)

    As always happens when I have issues, I try to solve it myself for hours on end, finally swallow my pride and post on the forums, and then find the solution on my own an hour later.
    Found the solution here: https://bbs.archlinux.org/viewtopic.php … 003#p70003
    I took the asound.conf that iphitus posted and changed the ctl.dmixer to use my sound card, which is PCH as determined by asound -l.
    here is my asound.conf:
    #/etc/asound.conf start:
    pcm.!default {
    type plug
    slave.pcm "dmixer"
    pcm.dsp0 {
    type plug
    slave.pcm "dmixer"
    pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
    pcm "hw:0,0"
    period_time 0
    period_size 1024
    buffer_size 8192
    rate 44100
    bindings {
    0 0
    1 1
    ctl.dmixer {
    type hw
    card PCH
    Last edited by tylerpnn (2014-03-29 06:01:42)

  • How many ALSA applications can play sound at once?

    I ran into a strange issue where I had Counter-Strike:GO running (sound working fine in the game itself) but when I alt-tabbed, no other application could play sound.  VLC would complain my device was busy and Chromium didn't show an error but sound didn't work either (tested with a YouTube video.)  I was able to solve this by changing the audio setting in CS:GO from 5.1 surround to 2 speaker (I use headphones so no need for surround) so now I can alt-tab and still have sound in other applications.
    What I want to know now is why that is?  Is there a limit to the number of simultaneous channels or what?  I just tested and with CS:GO set to 2 channel I can play sound from CS:GO, Chromium, VLC, and Banshee all at the same time but with 5.1 CS:GO hogs the sound card all to itself.
    I'm also curious about where PulseAudio fits into this.  Right now I'm just using pure ALSA.  If I were to get a surround setup one day would PulseAudio overcome this limitation and allow me to play music while I game?

    See list of gotchas.
    The main issue you probably have is that Dmix doesn't work with more than stereo - *unless* you use something like my sample config.
    ALSA is flexible, which means it will allow naughty apps to block the soundcard for other apps. So, configure your apps also.
    ALSA works fine, no need for pulseaudio.

  • How to play videos in java application

    Hi... every one
    I want to write a java application to play videos ....Please guide me how to go about it..
    Thanks in advance...
    Rgrds
    Ravi. N

    [http://www.cs.odu.edu/~cs778/spring04/lectures/jmfsolutions/examplesindex.html]

  • 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

  • Firefox won't play sound on youtube video's but sound works in other applications

    i can play sound as usual on other applications such as media player, vlc, itunes etc... but firefox and internet explorer do not work, google chrome doesnt even work. i have re-downloaded flash player and the pluggins many times trying to fix it, cleaned out my pc with ccleaner, anti-virus checked and such. i just cant fix it. i have before but i forget how and it always happens again after a while, especially just after pulling out speakers or headphones from the jack.
    == This happened ==
    Every time Firefox opened
    == it just keeps happening, has been for months and months

    Try clearing the Cache in Firefox.
    Tools-> Clear Recent History -> [v] Cache
    or
    Tools->Options->Advanced->Network -> Offline storage -> [Clear Now]
    Youtube may have made some changes recently. Clear the Youtube cookie and refresh page if above does not do it.

  • Playing sound from multiple applications?

    Hi, I recently started using Arch and I'm loving it but I have one problem. My ALSA can only play sound from one application at a time, so I have to use pulseaudio for the others. But pulseaudio doesn't recognize my mic so I can't remove ALSA. ALSA just says "device busy" or something. And yes I tried to search before posting but didn't find an answer.
    Thanks

    This is what I found from the logs:
    Jul 18 21:38:34 arch pulseaudio[946]: alsa-sink.c: ALSA woke us up to write new data to the device, but there was actually nothing to write!
    Jul 18 21:38:34 arch pulseaudio[946]: alsa-sink.c: Most likely this is a bug in the ALSA driver 'snd_hda_intel'. Please report this issue to the ALSA developers.
    Jul 18 21:38:34 arch pulseaudio[946]: alsa-sink.c: We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.
    Jul 19 00:53:54 arch pulseaudio[946]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 19 00:53:54 arch pulseaudio[946]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 19 21:59:22 arch pulseaudio[963]: alsa-sink.c: ALSA woke us up to write new data to the device, but there was actually nothing to write!
    Jul 19 21:59:22 arch pulseaudio[963]: alsa-sink.c: Most likely this is a bug in the ALSA driver 'snd_hda_intel'. Please report this issue to the ALSA developers.
    Jul 19 21:59:22 arch pulseaudio[963]: alsa-sink.c: We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.
    Jul 20 02:35:47 arch pulseaudio[963]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 20 02:35:47 arch pulseaudio[963]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 20 12:22:05 arch pulseaudio[981]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 20 12:22:05 arch pulseaudio[981]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 20 12:22:05 arch pulseaudio[981]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 21 01:25:49 arch pulseaudio[953]: alsa-sink.c: ALSA woke us up to write new data to the device, but there was actually nothing to write!
    Jul 21 01:25:49 arch pulseaudio[953]: alsa-sink.c: Most likely this is a bug in the ALSA driver 'snd_hda_intel'. Please report this issue to the ALSA developers.
    Jul 21 01:25:49 arch pulseaudio[953]: alsa-sink.c: We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.
    Jul 21 14:33:44 arch pulseaudio[973]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 21 14:33:44 arch pulseaudio[973]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 21 14:33:44 arch pulseaudio[973]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 22 01:58:04 arch pulseaudio[973]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 22 01:58:04 arch pulseaudio[973]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 22 02:20:11 arch pulseaudio[973]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 22 02:20:11 arch pulseaudio[973]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 22 02:48:30 arch pulseaudio[973]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 23 00:21:44 arch pulseaudio[973]: alsa-sink.c: ALSA woke us up to write new data to the device, but there was actually nothing to write!
    Jul 23 00:21:44 arch pulseaudio[973]: alsa-sink.c: Most likely this is a bug in the ALSA driver 'snd_hda_intel'. Please report this issue to the ALSA developers.
    Jul 23 00:21:44 arch pulseaudio[973]: alsa-sink.c: We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.
    Jul 23 11:43:46 arch pulseaudio[973]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 23 11:43:46 arch pulseaudio[973]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 23 11:43:56 arch pulseaudio[973]: alsa-sink.c: Error opening PCM device front:0: Device or resource busy
    Jul 24 03:05:32 arch pulseaudio[954]: alsa-sink.c: ALSA woke us up to write new data to the device, but there was actually nothing to write!
    Jul 24 03:05:32 arch pulseaudio[954]: alsa-sink.c: Most likely this is a bug in the ALSA driver 'snd_hda_intel'. Please report this issue to the ALSA developers.
    Jul 24 03:05:32 arch pulseaudio[954]: alsa-sink.c: We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.
    And yes I have gstreamer.
    Last edited by nerdster (2011-07-26 00:35:45)

Maybe you are looking for

  • Open iTunes and then Macbook Pro shuts off three seconds later

    i didnt see an easier way to post this so here it goes problem string is in red. its the same string before every shutdown CONSOLE SYSTEM LOG Aug 27 08:02:01 localhost bootlog[0]: BOOT_TIME 1346072521 0 Aug 27 08:02:13 localhost kernel[0]: PMAP: PCID

  • Why does my javascript code work fine in all other browsers, but not Safari

    Previously, I have asked how Safari handles javascript trying to resolve a problem with a slide menu, (http://www.designoutput.com/testslide.html) being directed to validator. I have corrected as many things as possible and still have code work in ot

  • Run Executable in LV 8.2

    I have an executable that was created in LV (8.5 or lower) that does X that was created and sent to me by the manufacturer of the device it controls (via USB).  When I open the executable, I have 1 line of user control by entering a string, but every

  • Apache - CGI script can't read query string from STDIN

    My Perl CGI script begins as follows: if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); I dumped all ENV variables at entry, and verified that REQUEST_METHOD = "POST" and CONTENT_LENGTH = 73 (which is correct). QUERY_STR

  • Insert images problems

    When I insert PNG images in Captivate 5.5, the outlines change color and become red, green, etc. I use PNG images because it allows me to have forms with the center transparent (like the gray lines in the video). Is it the format that causes problems