?? musicplay.java
字號:
package client;
/**
* <p>
* Copyright (C),2006
* Originally created 張成峰
* Revised by huanghao
*
* Desctiptoin: 主要描述聲音循環(huán)播放
* Functoin List:
* <Name> <Desc>
* 1、 構(gòu)造方法 線程啟動
* 2、 run 線程運(yùn)行
* 3、 main 創(chuàng)建實(shí)例,主函數(shù)運(yùn)行
* </p>
*
* @version 1.00
* @see Sprite
*/
import java.io.FileInputStream;
import sun.audio.AudioStream;
public class MusicPlay extends Thread{
FileInputStream music;//聲明文件流對象
private static final int SleepTime = 1500;
int i;
public boolean play = true;
AudioStream play_music;//聲明音頻流對象
/*
*構(gòu)造方法,線程啟動
*/
MusicPlay(){
this.start();
}
/*
*線程運(yùn)行
*/
public void run(){
//循環(huán)播放
while(play){
try{
i = (int)Math.floor(Math.random()*2);
music=new FileInputStream("./sound/bubble"+i+".wav");//創(chuàng)建文件流對象
//music=new FileInputStream("../windmusic.wav");
play_music=new sun.audio.AudioStream(music);//創(chuàng)建音頻流對象
}catch(Exception e){System.out.println(e);}
sun.audio.AudioPlayer.player.start(play_music);//開始播放
try{
if(i == 0)
Thread.sleep(6000);//音頻播放時間
else
Thread.sleep(3000);
}catch(Exception e){System.out.println(e);}
}
return;
}
/*
*主函數(shù)運(yùn)行。
*/
/* public static void main(String[] args){
new MusicPlay();
} */
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -