How can I play sound in Java?

后端 未结 10 800
傲寒
傲寒 2020-11-22 04:38

I want to be able to play sound files in my program. Where should I look?

10条回答
  •  礼貌的吻别
    2020-11-22 05:37

    A bad example:

    import  sun.audio.*;    //import the sun.audio package
    import  java.io.*;
    
    //** add this into your application code as appropriate
    // Open an input stream  to the audio file.
    InputStream in = new FileInputStream(Filename);
    
    // Create an AudioStream object from the input stream.
    AudioStream as = new AudioStream(in);         
    
    // Use the static class member "player" from class AudioPlayer to play
    // clip.
    AudioPlayer.player.start(as);            
    
    // Similarly, to stop the audio.
    AudioPlayer.player.stop(as); 
    

提交回复
热议问题