📄 playerui.java
字号:
ArrayList fileList = new ArrayList();
ArrayList folderList = new ArrayList();
ListIterator li = al.listIterator();
while (li.hasNext())
{
File f = (File) li.next();
if ((f.exists()) && (f.canRead()))
{
if (f.isFile()) fileList.add(f);
else if (f.isDirectory()) folderList.add(f);
}
}
playFiles(fileList);
// TODO : Add dir support
}
}
else if (data instanceof String)
{
String files = (String) data;
if ((files.length() > 0))
{
ArrayList fileList = new ArrayList();
ArrayList folderList = new ArrayList();
StringTokenizer st = new StringTokenizer(files, System.getProperty("line.separator"));
// Transfer files dropped.
while (st.hasMoreTokens())
{
String path = st.nextToken();
if (path.startsWith("file://"))
{
path = path.substring(7, path.length());
if (path.endsWith("\r")) path = path.substring(0, (path.length() - 1));
}
File f = new File(path);
if ((f.exists()) && (f.canRead()))
{
if (f.isFile()) fileList.add(f);
else if (f.isDirectory()) folderList.add(f);
}
}
playFiles(fileList);
// TODO : Add dir support
}
}
else
{
log.info("Unknown dropped objects");
}
}
/**
* Play files from a list.
* @param files
*/
protected void playFiles(List files)
{
if (files.size() > 0)
{
// Clean the playlist.
playlist.removeAllItems();
// Add all dropped files to playlist.
ListIterator li = files.listIterator();
while (li.hasNext())
{
File file = (File) li.next();
PlaylistItem pli = null;
if (file != null)
{
pli = new PlaylistItem(file.getName(), file.getAbsolutePath(), -1, true);
if (pli != null) playlist.appendItem(pli);
}
}
// Start the playlist from the top.
playlist.nextCursor();
playlistUI.initPlayList();
setCurrentSong(playlist.getCursor());
}
}
/**
* Sets the current song to play and start playing if needed.
* @param pli
*/
public void setCurrentSong(PlaylistItem pli)
{
int playerStateMem = playerState;
if ((playerState == PAUSE) || (playerState == PLAY))
{
try
{
theSoundPlayer.stop();
}
catch (BasicPlayerException e)
{
log.error("Cannot stop", e);
}
playerState = STOP;
secondsAmount = 0;
// Display play/time icons.
ui.getAcPlayIcon().setIcon(2);
ui.getAcTimeIcon().setIcon(0);
}
playerState = OPEN;
if (pli != null)
{
// Read tag info.
pli.getTagInfo();
currentSongName = pli.getFormattedName();
currentFileOrURL = pli.getLocation();
currentIsFile = pli.isFile();
currentPlaylistItem = pli;
}
// Playlist ended.
else
{
// Try to repeat ?
if (config.isRepeatEnabled())
{
if (playlist != null)
{
// PlaylistItems available ?
if (playlist.getPlaylistSize() > 0)
{
playlist.begin();
PlaylistItem rpli = playlist.getCursor();
if (rpli != null)
{
// OK, Repeat the playlist.
rpli.getTagInfo();
currentSongName = rpli.getFormattedName();
currentFileOrURL = rpli.getLocation();
currentIsFile = rpli.isFile();
currentPlaylistItem = rpli;
}
}
// No, so display Title.
else
{
currentSongName = Skin.TITLETEXT;
currentFileOrURL = null;
currentIsFile = false;
currentPlaylistItem = null;
}
}
}
// No, so display Title.
else
{
currentSongName = Skin.TITLETEXT;
currentFileOrURL = null;
currentIsFile = false;
currentPlaylistItem = null;
}
}
if (currentIsFile == true)
{
ui.getAcPosBar().setEnabled(true);
ui.getAcPosBar().setHideThumb(false);
}
else
{
config.setLastURL(currentFileOrURL);
ui.getAcPosBar().setEnabled(false);
ui.getAcPosBar().setHideThumb(true);
}
titleText = currentSongName.toUpperCase();
showMessage(titleText);
// Start playing if needed.
if ((playerStateMem == PLAY) || (playerStateMem == PAUSE))
{
processPlay(MouseEvent.BUTTON1_MASK);
}
}
/**
* Display text in title area.
* @param str
*/
public void showTitle(String str)
{
if (str != null)
{
currentTitle = str;
titleScrollLabel = null;
scrollIndex = 0;
scrollRight = true;
if (str.length() > TEXT_LENGTH_MAX)
{
int a = ((str.length()) - (TEXT_LENGTH_MAX)) + 1;
titleScrollLabel = new String[a];
for (int k = 0; k < a; k++)
{
String sText = str.substring(k, TEXT_LENGTH_MAX + k);
titleScrollLabel[k] = sText;
}
str = str.substring(0, TEXT_LENGTH_MAX);
}
ui.getAcTitleLabel().setAcText(str);
}
}
/**
* Shows message in title an updates bitRate,sampleRate, Mono/Stereo,time features.
* @param txt
*/
public void showMessage(String txt)
{
showTitle(txt);
ui.getAcSampleRateLabel().setAcText(" ");
ui.getAcBitRateLabel().setAcText(" ");
ui.getAcStereoIcon().setIcon(0);
ui.getAcMonoIcon().setIcon(0);
ui.getAcMinuteH().setAcText("0");
ui.getAcMinuteL().setAcText("0");
ui.getAcSecondH().setAcText("0");
ui.getAcSecondL().setAcText("0");
}
/**
* Toggle playlistUI.
*/
protected void togglePlaylist()
{
if (ui.getAcPlaylist().isSelected())
{
miPlaylist.setState(true);
config.setPlaylistEnabled(true);
loader.togglePlaylist(true);
}
else
{
miPlaylist.setState(false);
config.setPlaylistEnabled(false);
loader.togglePlaylist(false);
}
}
/**
* Toggle equalizerUI.
*/
protected void toggleEqualizer()
{
if (ui.getAcEqualizer().isSelected())
{
miEqualizer.setState(true);
config.setEqualizerEnabled(true);
loader.toggleEqualizer(true);
}
else
{
miEqualizer.setState(false);
config.setEqualizerEnabled(false);
loader.toggleEqualizer(false);
}
}
/**
* Returns a File from a filename.
* @param file
* @return
*/
protected File openFile(String file)
{
return new File(file);
}
/**
* Free resources and close the player.
*/
protected void closePlayer()
{
if ((playerState == PAUSE) || (playerState == PLAY))
{
try
{
if (theSoundPlayer != null)
{
theSoundPlayer.stop();
}
}
catch (BasicPlayerException e)
{
log.error("Cannot stop", e);
}
}
if (theSoundPlayer != null)
{
config.setAudioDevice(((BasicPlayer) theSoundPlayer).getMixerName());
}
if (ui.getAcAnalyzer() != null)
{
if (ui.getAcAnalyzer().getDisplayMode() == SpectrumTimeAnalyzer.DISPLAY_MODE_OFF) config.setVisualMode("off");
else if (ui.getAcAnalyzer().getDisplayMode() == SpectrumTimeAnalyzer.DISPLAY_MODE_SCOPE) config.setVisualMode("oscillo");
else config.setVisualMode("spectrum");
}
if (playlist != null)
{
playlist.save("default.m3u");
config.setPlaylistFilename("default.m3u");
}
loader.close();
}
/**
* Return current title in player.
* @return
*/
public String getCurrentTitle()
{
return currentTitle;
}
/**
* Try to compute time length in milliseconds.
* @param properties
* @return
*/
public long getTimeLengthEstimation(Map properties)
{
long milliseconds = -1;
int byteslength = -1;
if (properties != null)
{
if (properties.containsKey("audio.length.bytes"))
{
byteslength = ((Integer) properties.get("audio.length.bytes")).intValue();
}
if (properties.containsKey("duration"))
{
milliseconds = (int) (((Long) properties.get("duration")).longValue()) / 1000;
}
else
{
// Try to compute duration
int bitspersample = -1;
int channels = -1;
float samplerate = -1.0f;
int framesize = -1;
if (properties.containsKey("audio.samplesize.bits"))
{
bitspersample = ((Integer) properties.get("audio.samplesize.bits")).intValue();
}
if (properties.containsKey("audio.channels"))
{
channels = ((Integer) properties.get("audio.channels")).intValue();
}
if (properties.containsKey("audio.samplerate.hz"))
{
samplerate = ((Float) properties.get("audio.samplerate.hz")).floatValue();
}
if (properties.containsKey("audio.framesize.bytes"))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -