Clip not playing any sound

后端 未结 6 1017
迷失自我
迷失自我 2020-12-12 06:11

Well, the title says all, I tried playing a wav file using javax.sound and nothing is happening. I have tried many different files without any luck.

public s         


        
6条回答
  •  忘掉有多难
    2020-12-12 06:34

    Your program is terminating before the sound has the time to be played. I would do play.start(); in some threading way (invokeLater, ...), and also find a way to wait until the sound has finished (Reimeus suggested one).

    A lead :

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
    
              ...
    
              play.start();
              JOptionPane.showMessageDialog(null, "Click OK to stop music");
            }
        });
    
    }
    

提交回复
热议问题