The sound file not work

HI,
Here i want to get sound file then i want to play it . I did that but when i play it , it's not work .why ??
my code :
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.io.*;
import javax.sound.sampled.*;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.*;
public class SoundTest extends JFrame {
    private JPanel panel, mainPanel;
    //   private JTextField textField;
    private JButton getButton, playButton;
    private JFileChooser fileChooser;
    private MyActionListener myActionListener;
    public SoundTest() {
        myActionListener = new MyActionListener();
        panel = new JPanel(new BorderLayout());
        mainPanel = new JPanel(new FlowLayout());
        //       textField = new JTextField(10);
        getButton = new JButton("get audio file");
        getButton.addActionListener(myActionListener);
        playButton = new JButton("play");
        playButton.addActionListener(myActionListener);
        //     mainPanel.add(textField);
        mainPanel.add(getButton);
        mainPanel.add(playButton);
        panel.add(mainPanel, BorderLayout.WEST);
        getContentPane().add(panel);
        fileChooser = new JFileChooser();
    public static void main(String[] args) {
        SoundTest soundTest = new SoundTest();
        soundTest.setDefaultCloseOperation(SoundTest.EXIT_ON_CLOSE);
        soundTest.setSize(new Dimension(600, 300));
        soundTest.setLocationRelativeTo(null);
        soundTest.setVisible(true);
    private class MyActionListener implements ActionListener {
        SourceDataLine sourceDataLine = null;
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == getButton) {
                int returnValue = fileChooser.showOpenDialog(SoundTest.this);
                if (returnValue == JFileChooser.APPROVE_OPTION) {
                    File file = fileChooser.getSelectedFile();
                    crateAudio(file);
            } else if (e.getSource() == playButton) {
                playAudio();
        private void crateAudio(File file) {
            AudioInputStream audioInputStream = null;
            try {
                audioInputStream = AudioSystem.getAudioInputStream(file);
            } catch (UnsupportedAudioFileException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            AudioFormat audioFormat = audioInputStream.getFormat();
            DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
            try {
                sourceDataLine = (SourceDataLine) AudioSystem.getLine(info);
                sourceDataLine.open(audioFormat);
            } catch (LineUnavailableException ex) {
                ex.printStackTrace();
        private void playAudio() {
            sourceDataLine.start();
}Thanks in advnce

beshoyatefw wrote:
Here i want to get sound file then i want to play it . I did that but when i play it , it's not work .why ??Because there's no code that actually plays the file? Source data lines don't play the file when you open them, you have to manually read data from the AudioInputStream and write it to the SourceDataLine...and you're not doing that.
You essentially walked into the bathroom, lifted the toilet seat and unzipped your pants...and wondered why the toilet wasn't making that "I'm peeing" sound. It's because you didn't start actually moving urine from your bladder to the toilet...

Similar Messages

  • My iPhone 5s sounds stop working.i did not do anything it just stop working when I tried to turn on my music player all the sounds is not working I already check the volume and it is not also muted :( what happened can anyone solve my prob

    Hello everyone my iPhone 5s sounds stop working.i did not do anything it just stop working when I tried to turn on my music player all the sounds is not working I already check the volume and it is not also muted :( what happened can anyone solve my problem please

    Hey Kirby17,
    Thanks for using Apple Support Communities.
    If you are not getting any sound from the speaker, follow this article.
    iPhone: No sound or distorted sound from speaker
    http://support.apple.com/kb/ts5180
    Ensure that there is nothing plugged in to the headset jack or the dock connector.
    If the iPhone is in a protective case, make sure that the speaker port isn't blocked by the case.
    Make sure that the speaker and dock port aren't clogged with debris. If necessary, clean it with a clean, small, dry, soft-bristled brush. Carefully and gently brush away any debris.
    If an audio issue occurs when using a specific application, try testing other applications to see if the issue persists.
    If the iPhone is paired with a Bluetooth headset or car kit:
    Try turning off Bluetooth.
    If you experience difficulties with the Bluetooth feature, follow these troubleshooting steps.
    Restart the iPhone.
    If restarting doesn't fix the issue, ensure that your iPhone is updated to the latest version of iOS.
    If the issue is not resolved, please contact Apple Support.
    Have a nice day,
    Mario

  • Hi can you help the sound is not working on my Mac I have went into settings and there are no option for interal speaker help

    Hi can you help the sound is not working on my Mac I have went into settings and there are no option for interal speaker help

    Read the documentation at the links.  They won't hurt your data. 
    Basically smc reset is shutdown, pull your plug for 15 seconds, plug it back in, wait 5 seconds, and reboot.  Harmless to you.  Resets the smc.
    Pram reset is similar but you need to push commnd-option-P-R after the boot chime.  Read what does.
    smc and pram reset

  • The sound is not working on my iphone

    the sound is not working on my iphone it has suddenly stopped can someone please help me?

    None of these methods worked, so I just took a very thin paintbrush and dampened it using a Clorox wipe. Then, I just wiggled it around in the charging port. The sound worked for like 3 seconds then it stopped again. So I continued to clean it and it worked! After I listened to my music for about 30 minutes until it stopped again. I just blew hard into the port and it started working again. I think the problem was that the phone thought it was docked into speakers because it was so dirty. I think I'm going to get an Otterbox so this doesn't happen again. I hope I helped.

  • I have rented a movie in itunes and i wan't able to watch it because the sound did not work can i get my money refund

    i have rented a movie in thru apple tv and i wasn't able to watch it because the sound did not work can i get my money refund so i can rerent it

    Welcome to the Apple community.
    Select the content which is causing a problem and use the 'Report a problem' button in Your Purchase History.

  • Using my ATV3 since 1 year and now the sound is not working

    Using my ATV3 since 1 year and now the sound is not working, what is wrong?

    Jailbreaking, Unofficial unlocking, downgrading of iOS of iDevices neither welcomed not supported in this Forum.

  • I've just upgraded my Acer One S1001 to Windows 10 and realized that the sound is not working

    Hi everyone! I’ve just upgraded my Acer One S1001 to Windows 10 and realized that the sound is not working. When I went to the support site, I found that there are no drivers for Windows 10 yet!! Only drivers for Windows 8.1 are available. Please provide the drivers for Windows 10, otherwise I’m not able play sound from my machine. Can someone please help? Thanks.

    Try to install latest Realtek 2.79 version:http://www.realtek.com.tw/downloads/downloadsCheck.aspx?Langid=1&PNid=24&PFid=24&Level=4&Conn=3&DownTypeID=3&GetDown=false#High Definition Audio Codecs

  • In My IPhone the sound device not working properly. I can here the sound through head set only.kindly send an idea ti solve this problems

    In My IPhone the sound device not working properly. I can here the sound through head set only.kindly send an idea ti solve this problems

    Hello. I sent my WRT1900AC V1 to Linksys four days ago (Monday) via UPS with a RMA. Linksys paid the shipping and everything. The router is still in route, and it should arrive to their offices tomorrow. Once they receive the WRT1900 AC V1, they are going to send me an EA8500 as a replacement. But I have been reading the comments about the EA8500 here in the forum and it seems to have the same problems. I guess the firmware is extremely flawed in both routers (maybe it is almost the same code?). Anyway, I will try the EA8500 and I hope it works. I bought a temporary router from Walmart and I paid $35 for it. It is a Belink N600 DB. I can't believe that a $35 router is working a lot, lot, lot better than my previous $250 WRT1900AC router. Unbelievable. If the EA8500 doesn't work, I'm going to try and get my money back from Linksys, or contact The Consumerist or someone to get my money back and get a Nighthawk instead.

  • My ipod say it has headphones in when it does not so the sound does not work. What do i do? I have already reset it a lot.

    My ipod sound is not working! I dropped it in water and it works fine but i can not hear anything. It say theat it has headphones in but there are no headphones in. What do i do? I have already reset it.

    Glad to have helped. One more thing to try, after drying your iPod. Try plugging and unplugging the headphone jack quickly about 12 times, it could be that the switch inside the port is stuck, many times this action will un-stick it. If the problem continues you may need to look into purchasing an out of warranty iPod, refurbished one are cheaper. Also, if you have not already done so, BACKUP ALL YOUR STUFF from this iPod to your computer, water damaged iPods have a habit of stop working without any notice. Hope this helps, Good luck.

  • TS5180 The sound is not working on my Iphone5, what do I do?

    Sound is not working on Iphone. Have gone to settings and checked to besure sound is on, etc.

    They are giving superficial solution in that post. I think the problem could be software (developers should look into it). I have this problem too, the speaker works with voice memo and ringtone but not with the notifications and apps. Apple is not taking care of this issue and they should resolve it as soon as possible.

  • The sound is not working properly on my laptop

    The past 2 days I've been having problems with the sound on my laptop which is an Hp Pavilion 15 Notebook PC. When I restart it, it works fine but if I pause something im watching and come back to it the sound is no longer working. I also notice that when this happens if I hit the mute button it doesn't light up orange but it does show the mute icon. I'm not that good with computers...I tried troubleshooting it, it says theres nothing wrong. Im confused, please help!

    Try this:
    In the device manager locate the IDT High Definition Audio CODEC under sound, game and video controller.
    Right click and select uninstall.
    Restart your computer and open up the device manager again.
    In the same spot under sound, game and video controller where the IDT CODEC used to be listed there will be something else listed.
    Right click on that and select "scan for hardware changes" this will reinstall the IDT CODEC but I believe it is the updated driver which is actually compatible.
    It has been working for me so far, but I will keep you updated if it fails again. For now  I would try that!! good luck

  • TS3274 the sound is not working on my ipad, it stops working on and off, will work with ear phones and then it will stop working

    the sound on my ipad is not working.  It will work on and off and then cut out all together.  Sometimes if I use the ear phones it will work for a while and then it will cut out all together

    Reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

  • I`ve updating my iphoneto version 6 but the sound button not working even there is no any sound when i use any application

    I`veupdating my iphone to version 6 but the buttons of sound not working even more the soundsof all app was lost

    any body have an idea about my problem?

  • The sound is not working on the ipod nano

    have ipod nano and sound is not working

    Had that problem.  Make sure you push the buds wire all the way in. Hope it helps.

  • Sound file not working online

    Hi,
    Am creating a file for public access through Dropbox. Am on a MacBook running Mountain Lion and using Acrobat Pro X. This is the first time I have tried doing anything more complicated than just creating simple documents.
    I created a 2-page document in Pages and saved as a pdf. Then I added a short mp3 through the Multimedia > Sound option. It works well on my computer, but when added to Dropbox, it does not activate (unless downloaded back to computer).
    Should it work online? I'm sure it must, so I'm missing something.
    Any advice gratefully received,
    TIA
    Graham

    Heidenreich12...see if the info in this link sorts out the problem
    http://docs.info.apple.com/article.html?artnum=300832

Maybe you are looking for

  • Generating a Report from a Servlet in a new Browser using javascript:

    Hi, folks, I'm facing an intersting problem: I have the servlet below that generates a new browser with a click of a button. But if the parameter of the function gera(), have the caracter ' (pics), for example: gera( '<img src='name'>' ), the functio

  • No password needed?

    I have an iphone4, updated to the new iOS6. Now it no longer requires my password to purchase itunes or apps. How do I turn it back on?

  • Integrating DropDown menu of flash with director

    Hi everyone, I have a movie wherein i am using small flash movies as component for better UI effect. Also we are using other component like drop down, text boxes and radio buttons developed in flash. But the controls that we have in flash are causing

  • Gateway Sample

    Hey Martin, It wud be gr8 if U can give some example of enabling Alternative 2 for gateways (Exclusive). I am facing issue while evaluating condition for gateway...(Alternative2). Probably using a Scenario as given below would be of much help to me :

  • Modify permissions on a document center site

    I have a document center site that has a number of folders. It appears as if the default "inherit from parent" permissions are applied. One a couple of those folders, I need to modify the permissions by removing a group, but not from the other folder