📄 player.java
字号:
if ((playerState == INIT) || (playerState == STOP) || (playerState == OPEN))
{
System.gc();
PlaylistItem pli = null;
// Local File.
if (acEject.getMouseButton() == MouseEvent.BUTTON1_MASK)
{
FileDialog FD = new FileDialog(new Frame(),"Open file",FileDialog.LOAD);
FD.show();
if (FD.getFile() != null) pli = new PlaylistItem(FD.getFile(), FD.getDirectory()+FD.getFile(), -1, true);
}
// Remote File.
else if (acEject.getMouseButton() == MouseEvent.BUTTON3_MASK)
{
UrlDialog UD = new UrlDialog("Open location",100,100,280,120,config.getLastURL());
UD.show();
if (UD.getFile() != null) pli = new PlaylistItem(UD.getFile(), UD.getURL(), -1, false);
}
this.setCurrentSong(pli);
}
offScreenGraphics.drawImage(iconsImage[2], iconsLocation[0], iconsLocation[1], this);
offScreenGraphics.drawImage(iconsImage[4], iconsLocation[2], iconsLocation[3], this);
repaint();
}
/*---------------------------*/
/*-- Play the current File --*/
/*---------------------------*/
else if (e.getActionCommand().equals("Play"))
{
if (playerState == PAUSE)
{
theSoundPlayer.resumePlayback();
playerState = PLAY;
offScreenGraphics.drawImage(iconsImage[0], iconsLocation[0], iconsLocation[1], this);
offScreenGraphics.drawImage(iconsImage[3], iconsLocation[2], iconsLocation[3], this);
repaint();
}
else if (playerState == PLAY)
{
theSoundPlayer.stopPlayback();
playerState = PLAY;
secondsAmount = 0;
offScreenGraphics.drawImage(timeImage[0], minuteDLocation[0], minuteDLocation[1], this);
offScreenGraphics.drawImage(timeImage[0], minuteLocation[0], minuteLocation[1], this);
offScreenGraphics.drawImage(timeImage[0], secondDLocation[0], secondDLocation[1], this);
offScreenGraphics.drawImage(timeImage[0], secondLocation[0], secondLocation[1], this);
repaint();
if (currentFileOrURL != null)
{
try
{
if (currentIsFile == true) theSoundPlayer.setDataSource(openFile(currentFileOrURL));
else theSoundPlayer.setDataSource(new URL(currentFileOrURL));
} catch (Exception ex)
{
trace(0,getClass().getName(),"Cannot read file : "+currentFileOrURL+", "+ex.getMessage());
}
theSoundPlayer.startPlayback();
}
}
else if ( (playerState == STOP) || (playerState == OPEN))
{
if (currentFileOrURL != null)
{
try
{
if (currentIsFile == true) theSoundPlayer.setDataSource(openFile(currentFileOrURL));
else theSoundPlayer.setDataSource(new URL(currentFileOrURL));
} catch (UnsupportedAudioFileException uafe)
{
trace(0,getClass().getName(),"Stream error :"+currentFileOrURL+", "+uafe.getMessage());
}
catch (LineUnavailableException lue)
{
trace(0,getClass().getName(),"Stream error :"+currentFileOrURL+", "+lue.getMessage());
}
catch (IOException ex)
{
trace(0,getClass().getName(),"Stream error :"+currentFileOrURL+", "+ex.getMessage());
}
theSoundPlayer.startPlayback();
theSoundPlayer.setGain( ((double)gainValue / (double)maxGain) );
theSoundPlayer.setPan((float)balanceValue);
sampleRateImage = (new taftb(fontIndex, imText, fontWidth, fontHeight, 0, ""+Math.round((theSoundPlayer.getAudioFormat()).getSampleRate()/1000))).getBanner();
bitsRateImage = (new taftb(fontIndex, imText, fontWidth, fontHeight, 0, ""+Math.round((theSoundPlayer.getAudioFormat()).getFrameSize()*8*(theSoundPlayer.getAudioFormat()).getFrameRate()/1000))).getBanner();
offScreenGraphics.drawImage(sampleRateImage, sampleRateLocation[0], sampleRateLocation[1], this);
offScreenGraphics.drawImage(bitsRateImage, bitsRateLocation[0], bitsRateLocation[1], this);
if ((theSoundPlayer.getAudioFormat()).getChannels() == 2)
{
offScreenGraphics.drawImage(activeModeImage[0], stereoLocation[0], stereoLocation[1], this);
}
else if ((theSoundPlayer.getAudioFormat()).getChannels() == 1)
{
offScreenGraphics.drawImage(activeModeImage[1], monoLocation[0], monoLocation[1], this);
}
double lenghtInSecond = 0.0;
if ((theSoundPlayer.getAudioFileFormat()).getFrameLength() != -1 ) lenghtInSecond = ((theSoundPlayer.getAudioFileFormat()).getFrameLength()*theSoundPlayer.getAudioFormat().getFrameSize()*8)/((theSoundPlayer.getAudioFormat()).getFrameSize()*8*(theSoundPlayer.getAudioFormat()).getFrameRate());
else lenghtInSecond = ((theSoundPlayer.getAudioFileFormat()).getByteLength()*8)/((theSoundPlayer.getAudioFormat()).getFrameSize()*8*(theSoundPlayer.getAudioFormat()).getFrameRate());
int minutes = (int) (lenghtInSecond/60);
int seconds = (int) (lenghtInSecond - (minutes*60));
titleText = currentSongName.toUpperCase();
if (seconds >= 10) titleText = titleText + " ("+minutes+":"+seconds+")";
else titleText = titleText + " ("+minutes+":0"+seconds+")";
titleImage = (new taftb(fontIndex, imText, fontWidth, fontHeight, 0, titleText)).getBanner(0,0,155,6);
offScreenGraphics.drawImage(clearImage, titleLocation[0], titleLocation[1], this);
offScreenGraphics.drawImage(titleImage, titleLocation[0], titleLocation[1], this);
offScreenGraphics.drawImage(timeImage[0], minuteDLocation[0], minuteDLocation[1], this);
offScreenGraphics.drawImage(timeImage[0], minuteLocation[0], minuteLocation[1], this);
offScreenGraphics.drawImage(timeImage[0], secondDLocation[0], secondDLocation[1], this);
offScreenGraphics.drawImage(timeImage[0], secondLocation[0], secondLocation[1], this);
playerState = PLAY;
offScreenGraphics.drawImage(iconsImage[0], iconsLocation[0], iconsLocation[1], this);
offScreenGraphics.drawImage(iconsImage[3], iconsLocation[2], iconsLocation[3], this);
repaint();
trace(1,getClass().getName(),titleText);
if ((theSoundPlayer.getAudioFileFormat()).getFrameLength() != -1 ) trace(1,getClass().getName(),"Frames = "+(theSoundPlayer.getAudioFileFormat()).getFrameLength());
trace(1,getClass().getName(),"FrameRate (Hz) = "+theSoundPlayer.getAudioFormat().getFrameRate());
trace(1,getClass().getName(),"FrameSize (bits) = "+theSoundPlayer.getAudioFormat().getFrameSize()*8);
}
}
}
/*-----------------------------------*/
/*-- Pause/Resume the current File --*/
/*-----------------------------------*/
else if (e.getActionCommand().equals("Pause"))
{
if (playerState == PLAY)
{
theSoundPlayer.pausePlayback();
playerState = PAUSE;
offScreenGraphics.drawImage(iconsImage[1], iconsLocation[0], iconsLocation[1], this);
offScreenGraphics.drawImage(iconsImage[4], iconsLocation[2], iconsLocation[3], this);
repaint();
}
else if (playerState == PAUSE)
{
theSoundPlayer.resumePlayback();
playerState = PLAY;
offScreenGraphics.drawImage(iconsImage[0], iconsLocation[0], iconsLocation[1], this);
offScreenGraphics.drawImage(iconsImage[3], iconsLocation[2], iconsLocation[3], this);
repaint();
}
}
/*------------------*/
/*-- Stop to play --*/
/*------------------*/
else if (e.getActionCommand().equals("Stop"))
{
if ( (playerState == PAUSE) || (playerState == PLAY))
{
theSoundPlayer.stopPlayback();
playerState = STOP;
secondsAmount = 0;
acPosBar.setLocation(posBarBounds[0],posBarLocation[1]);
offScreenGraphics.drawImage(iconsImage[2], iconsLocation[0], iconsLocation[1], this);
offScreenGraphics.drawImage(iconsImage[4], iconsLocation[2], iconsLocation[3], this);
repaint();
}
}
/*----------*/
/*-- Next --*/
/*----------*/
else if (e.getActionCommand().equals("Next"))
{
// Try to get next song from the playlist
playlist.nextCursor();
PlaylistItem pli = playlist.getCursor();
this.setCurrentSong(pli);
}
/*--------------*/
/*-- Previous --*/
/*--------------*/
else if (e.getActionCommand().equals("Previous"))
{
// Try to get previous song from the playlist
playlist.previousCursor();
PlaylistItem pli = playlist.getCursor();
this.setCurrentSong(pli);
}
/*--------------------------------------------*/
/*-- Exit window through Exit Button --*/
/*--------------------------------------------*/
else if (e.getActionCommand().equals("Exit"))
{
if ( (playerState == PAUSE) || (playerState == PLAY))
{
theSoundPlayer.stopPlayback();
}
dispose();
System.gc();
System.exit(0);
}
/*--------------------------------------------*/
/*-- Move full window through its Title Bar --*/
/*--------------------------------------------*/
else if (e.getActionCommand().equals("TitleBar"))
{
//trace(3,getClass().getName(),"X="+acTitle.getMouseX()+" Y="+acTitle.getMouseY());
if (acTitleBar.isMousePressed() == false) FirstDrag = true;
else
{
int DeltaX = 0;
int DeltaY = 0;
if (FirstDrag == false)
{
DeltaX = acTitleBar.getMouseX() - XDrag;
DeltaY = acTitleBar.getMouseY() - YDrag;
XDrag = acTitleBar.getMouseX() - DeltaX;
YDrag = acTitleBar.getMouseY() - DeltaY;
OrigineX = OrigineX + DeltaX;
OrigineY = OrigineY + DeltaY;
setLocation(OrigineX,OrigineY);
}
else
{
FirstDrag = false;
XDrag = acTitleBar.getMouseX();
YDrag = acTitleBar.getMouseY();
}
}
}
else
{
}
}
public void paint(Graphics g)
{
if (offScreenImage != null)
{
g.drawImage(offScreenImage, 0, 0, this);
}
}
public void update(Graphics g)
{
//System.out.println("Update");
paint(g);
}
/*-- Invoked when the mouse has been clicked on a component --*/
//public void mouseClicked(MouseEvent me)
//{}
/*-- Invoked when the mouse enters a component --*/
//public void mouseEntered(MouseEvent me)
//{}
/*-- Invoked when the mouse exits a component --*/
//public void mouseExited(MouseEvent me)
//{}
/*-- Invoked when a mouse button has been pressed on a component --*/
//public void mousePressed(MouseEvent me)
//{}
/*-- Invoked when a mouse button has been released on a component --*/
//public void mouseReleased(MouseEvent me)
//{}
//public void mouseDragged(MouseEvent me)
//{}
//public void mouseMoved(MouseEvent me)
//{}
private File openFile(String file)
{
return new File(file);
}
public void setSkin(String sk)
{
thePath=sk;
}
/**
* Sends traces to Debug.
*/
private void trace(int level, String msg1, String msg2)
{
Debug dbg = Debug.getInstance();
dbg.log(level,msg1+":"+msg2);
}
/**
* Entry point.
*/
public static void main(String[] args)
{
Player theGUI;
String currentArg = null;
String currentValue = null;
String skin = null;
String logfile = null;
int loglevel = 0;
for (int i=0;i<args.length;i++)
{
currentArg = args[i];
if (currentArg.startsWith("-"))
{
if (currentArg.toLowerCase().equals("-skin"))
{
i++;
if (i >= args.length) usage("skin value missing");
currentValue = args[i];
skin = currentValue.replace('\\', '/').replace('/',java.io.File.separatorChar);
}
else if (currentArg.toLowerCase().equals("-loglevel"))
{
i++;
if (i >= args.length) usage("loglevel value missing");
currentValue = args[i];
try
{
loglevel = Integer.parseInt(currentValue);
} catch (NumberFormatException nfe)
{
usage("Invalid number : "+nfe.getMessage());
}
}
else if (currentArg.toLowerCase().equals("-logfile"))
{
i++;
if (i >= args.length) usage("logfile value missing");
currentValue = args[i];
logfile = currentValue.replace('\\', '/').replace('/',java.io.File.separatorChar);
}
else usage("Unknown parameter : "+currentArg);
}
else
{
usage("Invalid parameter :"+currentArg);
}
}
theGUI= new Player(skin, loglevel, logfile);
theGUI.show();
}
/**
* Displays usage.
*/
private static void usage(String msg)
{
System.out.println("jlGui 2.0 : "+msg);
System.out.println("");
System.out.println("jlGui 2.0 : Usage");
System.out.println(" java javazoom.jlGui.Player [-skin skinFilename] [-loglevel number] [-logfile logFilename]");
System.out.println("");
System.out.println(" skinFilename : Filename to a Winamp Skin2.x");
System.out.println(" number : Level of traces (0,1,2)");
System.out.println(" logFilename : Filename for traces");
System.out.println("");
System.out.println("Homepage : http://www.javazoom.net");
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -