zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package PbuliClass;
import java.io.File;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
/**¸ÃÀàÓÃÓÚµ÷Óò¥·ÅÉùÒôÎļþ*/
public class Music extends Thread {
    static String voicetime=null;
    private String musicName;//ÒôƵÎļþÃû³Æ
    public Music(String musicName)
    {
        this.musicName=musicName;
    }
 
    public void run() {
 
        File name = new File(musicName);
        AudioInputStream ypsrl = null;
        try {
            ypsrl = AudioSystem.getAudioInputStream(name);
        } catch (Exception e){}
 
        AudioFormat format = ypsrl.getFormat();
        SourceDataLine aqsj = null;
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
 
        try {
            aqsj = (SourceDataLine) AudioSystem.getLine(info);
            if(aqsj !=null) {
            aqsj.open(format);
            aqsj.start();
            }
        } catch (Exception e){
            
        }        
        
 
        int zjtj = 0;
        byte[] hczj = new byte[1024];
        try {
            while (zjtj  != -1) {
                zjtj = ypsrl.read(hczj, 0, hczj.length);
                if (zjtj  >= 0)
                    aqsj.write(hczj, 0, zjtj );
            }
        } catch (Exception e){}
        finally {
            if(aqsj !=null) {
            aqsj.drain();//½«²ÐÁô²¿·Ö´¦Àí¸É¾»
            aqsj.close();
            }
        }
    }
 
    /**»ñÈ¡ÉùÒô±»´¥·¢µÄʱ¼ä*/
    public static String getVoicetime() {
        return voicetime;
    }
 
    public static void setVoicetime(String voicetime) {
        Music.voicetime = voicetime;
    }    
}