📄 playerui.java
字号:
total = (long) Math.round(getTimeLengthEstimation(audioInfo) / 1000); currentItem.setDuration(total); playlistUI.repaint(); } // If it fails again then it might be stream => Total = -1 if (total <= 0) { total = -1; } if (audioInfo.containsKey("basicplayer.sourcedataline")) { // Spectrum/time analyzer if (audioChart != null) { audioChart.writeDSP(pcmdata); } } if (audioInfo.containsKey("audio.length.bytes")) { byteslength = ((Integer) audioInfo.get("audio.length.bytes")).intValue(); } float progress = -1.0f; if ((bytesread > 0) && ((byteslength > 0))) { progress = bytesread * 1.0f / byteslength * 1.0f; config.setLastRate(progress); } if (audioInfo.containsKey("audio.type")) { String audioformat = (String) audioInfo.get("audio.type"); if (audioformat.equalsIgnoreCase("mp3")) { //if (properties.containsKey("mp3.position.microseconds")) secondsAmount = (long) Math.round(((Long) properties.get("mp3.position.microseconds")).longValue()/1000000); // Shoutcast stream title. if (properties.containsKey("mp3.shoutcast.metadata.StreamTitle")) { String shoutTitle = ((String) properties.get("mp3.shoutcast.metadata.StreamTitle")).trim(); if (shoutTitle.length() > 0) { if (currentItem != null) { String sTitle = " (" + currentItem.getFormattedDisplayName() + ")"; if (!currentItem.getFormattedName().equals(shoutTitle + sTitle)) { currentItem.setFormattedDisplayName(shoutTitle + sTitle);// showTitle((shoutTitle + sTitle).toUpperCase());// playlistUI.paintList(); } } } } // EqualizerUI if (properties.containsKey("mp3.equalizer")) { equalizerUI.setBands((float[]) properties.get("mp3.equalizer")); } if (total > 0) { secondsAmount = (long) (total * progress); } else { secondsAmount = -1; } } else if (audioformat.equalsIgnoreCase("wave")) { secondsAmount = (long) (total * progress); } else { secondsAmount = (long) Math.round(microseconds / 1000000); equalizerUI.setBands(null); } } else { secondsAmount = (long) Math.round(microseconds / 1000000); equalizerUI.setBands(null); } if (secondsAmount < 0) { secondsAmount = (long) Math.round(microseconds / 1000000); }// //如果歌曲里面有位置的信息,则设置歌词// if (properties.containsKey("mp3.position.microseconds")) {// int mill = (int) ((Long) properties.get("mp3.position.microseconds") / 1000);// if (lyric != null) {// lyric.setTime(mill);// }// } else {//如果不是MP3的格式,则歌词的显示就没有那么精确了,但是还需要滚动// if (lyric != null) {//// lyric.setTime((secondsAmount * 1000));// lyric.setTime(microseconds / 1000);// }// } /*-- Display elapsed time --*/ int seconds = (int) secondsAmount; timePanel.setTime(seconds); // Update PosBar location. if (total != 0) { if (posValueJump == false) { int pValue = (Math.round(secondsAmount * Config.POSBARMAX / total)); pos.setValue(pValue); } } else { pos.setValue(0); } long ctime = System.currentTimeMillis(); long lctime = lastScrollTime; // Scroll title ?//这里可能是显示歌曲信息如果显示不下时的换行做法// if ((titleScrollLabel != null) && (titleScrollLabel.length > 0)) {// if (ctime - lctime > SCROLL_PERIOD) {// lastScrollTime = ctime;// if (scrollRight == true) {// scrollIndex++;// if (scrollIndex >= titleScrollLabel.length) {// scrollIndex--;// scrollRight = false;// }// } else {// scrollIndex--;// if (scrollIndex <= 0) {// scrollRight = true;// }// }// // TODO : Improve// skin.getAcTitleLabel().setAcText(titleScrollLabel[scrollIndex]);// }// } } public void setLyric(Lyric ly) { this.lyric = ly; if (currentItem != null) { currentItem.setLyricFile(ly.getLyricFile()); } } public void setTime(long time) { if (time < 0) { return; } if (currentItem != null) { long length = currentItem.getLength() * 1000; if (length < 0) { return; } double rate = time * 1.0 / length; processSeek(rate); } } public void saveConfig() { } public void readConfig() { } public void setShowLyric(boolean b) { lrc.setSelected(b); lrc.setActionCommand(b ? Config.LRC_OFF : Config.LRC_ON); loader.toggleLyricWindow(b); } public JFrame getTopParent() { return config.getTopParent(); } public void play() { processPlay(0); } public void pause() { processPause(0); } public void stop() { processStop(0); } public void nextSong() { processNext(0); } public void previousSong() { processPrevious(0); } public void actionPerformed(ActionEvent e) { final ActionEvent evt = e; if (e.getActionCommand().equals(Config.PAUSE)) { processActionEvent(e); } else if ((e.getActionCommand().equals(Config.PLAY)) && (playerState == PAUSE)) { processActionEvent(e); } else if (e.getActionCommand().equals(Config.CLOSE)) { closePlayer(); } else if (e.getActionCommand().equals(Config.MINIMIZE)) { loader.minimize(); } else if (e.getActionCommand().equals(Config.SETTING)) { OptionDialog jd = new OptionDialog(config.getTopParent(), true); jd.setTitle("关于"); jd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); jd.setVisible(true); } else { //其它的都是比较耗时的操作,所以新起一个线程去做 new Thread("PlayerUIActionEvent") { public void run() { processActionEvent(evt); } }.start(); } } public void processStop(int modifiers) { if ((playerState == PAUSE) || (playerState == PLAY)) { try { player.stop(); } catch (BasicPlayerException e) { } playerState = STOP; secondsAmount = 0; pos.setValue(0); timePanel.reset(); //这里清空一些东西,比如时间归0,播放按钮变成一个可播放的标志,而不是暂停的标志// skin.getAcPlayIcon().setIcon(2);// skin.getAcTimeIcon().setIcon(1); pos.setEnabled(false); changePlayPauseState(playerState); } } /** * 这里处理关闭播放器的方法, * 关闭的时候要保存目录的所有配置,然后再释放资源 */ protected void closePlayer() { log.log(Level.INFO, "调用了closePlayer"); if ((playerState == PAUSE) || (playerState == PLAY)) { try { if (player != null) { player.stop(); } } catch (BasicPlayerException e) { } } config.setGainValue(volume.getValue()); config.setPanValue(pan.getValue()); loader.close(); } public PlayListItem getCurrentItem() { return currentItem; } public void setPlayerState(int state) { this.playerState = state; } public void setCurrentSong(PlayListItem pli) { seekedTime=0L; log.log(Level.INFO, "调用了setCurrentSong()" + Thread.currentThread()); if (config.getReadTagInfoStrategy().equals(Config.READ_WHEN_PLAY)) { pli.getTagInfo(); } currentItem = pli; playlistUI.setCurrentItem(pli); int playerStateMem = playerState; if ((playerState == PAUSE) || (playerState == PLAY)) { try { player.stop(); } catch (BasicPlayerException e) { } playerState = STOP; secondsAmount = 0; timePanel.reset(); // Display play/time icons. //把播放和时间的图标变成最初的状态// skin.getAcPlayIcon().setIcon(2);// skin.getAcTimeIcon().setIcon(0); } playerState = OPEN; if (pli != null) { // Read tag info. pli.getTagInfo(); infoPanel.repaint(); currentSongName = pli.getFormattedName(); currentFileOrURL = pli.getLocation(); currentIsFile = pli.isFile(); } // 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(); currentItem = rpli; } } // No, so display Title. else { currentSongName = Config.TITLETEXT; currentFileOrURL = null; currentIsFile = false; currentItem = null; } } } // No, so display Title. else { currentSongName = Config.TITLETEXT; currentFileOrURL = null; currentIsFile = false; currentItem = null; } } if (currentIsFile == true) { pos.setEnabled(true); pos.setHideThumb(false); } else { pos.setValue(0); pos.setEnabled(false); pos.setHideThumb(true); } config.setCurrentFileOrUrl(currentFileOrURL); //这里可能是要显示歌名以及此歌曲的一些信息 titleText = currentSongName.toUpperCase(); showMessage(titleText); playlist.setItemSelected(pli, playlist.getSelectedIndex()); playlistUI.repaint(); // Start playing if needed. if ((playerStateMem == PLAY) || (playerStateMem == PAUSE)) { processPlay(MouseEvent.BUTTON1_MASK); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -