?? mp3player.java
字號(hào):
package paly;
import java.io.File;
import java.util.Vector;
import javax.media.Manager;
import javax.media.Player;
public class Mp3Player extends Thread{
private Mp3State mp3;
private int songlistLength;
private Vector<String> songlist;
private Player player = null;
public Mp3Player(Mp3State mp3){
this.mp3 = mp3;
songlistLength = mp3.getSonglist().size();
songlist = mp3.getSonglist();
}
public void run(){
int currentIndex;
double currentTime = 0;
double currentDuration = -1;
while((currentIndex = mp3.getCurrentIndex()) <= songlistLength){
if(mp3.getTriggerStart() && (currentTime >= currentDuration)){
try{
File currentSong = new File(songlist.elementAt(currentIndex));
player = Manager.createRealizedPlayer(currentSong.toURL());
mp3.setPlayer(player);
if(mp3.getIsPaused()){
player.setMediaTime(mp3.getPauseTime());
}
player.start();
System.out.println(currentSong.getName());
System.out.print(">>>");
mp3.setIsStarted(true);
currentDuration = player.getDuration().getSeconds();
} catch(Exception e){
System.out.println(e);
}
mp3.setCurrentIndex(currentIndex + 1);
}
if(mp3.getIsStarted()){
currentTime = player.getMediaTime().getSeconds();
} else {
currentTime = 0;
currentDuration = -1;
}
try{
Thread.sleep((int)(Math.random() * 500));
} catch (InterruptedException e){}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -