why this code doesn't play the sound file

后端 未结 3 1521
别那么骄傲
别那么骄傲 2020-12-19 22:34

The code

import javax.sound.sampled.*;
import java.io.*;

public class Tester {
static Thread th;


public static void main(String[] args) {
    sta         


        
3条回答
  •  长情又很酷
    2020-12-19 23:14

    import javax.sound.sampled.*;
    import java.io.*;
    import javax.swing.*;
    
    public class Tester {
    static Thread th;
    
    
    public static void main(String[] args) throws Exception {
         Clip clip = AudioSystem.getClip();
         AudioInputStream ais = AudioSystem.getAudioInputStream(new File("d:/UnderTest/wavtester.wav"));
         clip.open(ais);
         clip.loop(0);
         // Calculate totalFrames
         long totalFrames = (long)(clip.getFrameLength() * clip.getFormat().getFrameRate());
         Thread.sleep( ( totalFrames* 1000 )); // pause the thread till the sound plays
    
         System.out.println(clip.getFrameLength());
         System.out.println(clip.getFormat().getFrameRate());           
     }
    }
    

提交回复
热议问题