How to play audio in Java Application

前端 未结 4 2005
悲&欢浪女
悲&欢浪女 2020-12-07 05:40

I\'m making a java application and I need to play audio. I\'m playing mainly small sound files of my cannon firing (its a cannon shooting game) and the projectiles exploding

4条回答
  •  我在风中等你
    2020-12-07 06:30

    For the first method you have to create another thread for audio.

    For example like this:

    new Thread(
                new Runnable() {
                    public void run() {
                        try {
                            // PLAY AUDIO CODE
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
    

    Of course you have to make sure that previous sound isn't still playing.

提交回复
热议问题