Playing an audio file on JButton press?

2020-02-15 09:09发布

I've looked on Google for a while, searching how to play audio files, and most of the sources I found were with using java.applet.*, but I am trying to look for a way I can put it inside my actionPerformed() method.

public void actionPerformed(ActionEvent event) {
    if(event.getActionCommand().equals("Play")){
        //Short Audio File Playing Here
    }
}

2条回答
一夜七次
2楼-- · 2020-02-15 10:04

You may learn and use javax.sound API. Have a look at tutorial - Playing Back Audio.

查看更多
仙女界的扛把子
3楼-- · 2020-02-15 10:09

See the JavaSound info. page for the "Playing a Clip" section.

查看更多
登录 后发表回答