Home Can't play sound in java using clip
Reply: 0

Can't play sound in java using clip

user913
1#
user913 Published in June 20, 2018, 12:03 am

I want to play some sound in java using this code bellow. That sound is in WAV format so I think that this code should work fine, but instead of playing sound it simply does nothing. There is no even error on my console. So can someone help me to make this code play sound. (this sound is included inside one package in my src file)

 public static void main(String[] args) {

 new Thread(new Runnable() {

        @Override
        public void run() {

            try {

                Clip clip = AudioSystem.getClip();

                File file = new File("C:\\Users\\Jovan\\Desktop\\song.wav");

                AudioInputStream inputStream = AudioSystem.getAudioInputStream(file);

                clip.open(inputStream);

                clip.start();

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    });
 }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.325715 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO