📄 playerui.java
字号:
return menu; } private JMenu createLyricMenu() { JMenu menu = new JMenu(Config.getResource("PlayerUI.lrc")); Util.generateLyricMenu(menu, lyricUI.getLyricPanel()); return menu; } private JMenu createEqMenu() { JMenu menu = new JMenu(Config.getResource("PlayerUI.eq")); menu.add(new AbstractAction(Config.getResource("PlayerUI.autoConfig")) { public void actionPerformed(ActionEvent e) { equalizerUI.getAutoButton().doClick(); } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.onoff")) { public void actionPerformed(ActionEvent e) { equalizerUI.getOnOffButton().doClick(); } }); menu.addSeparator(); JMenu selects = new JMenu(Config.getResource("PlayerUI.selectableTypes")); for (String s : EqualizerUI.presets) { JMenuItem item = new JMenuItem(Config.getResource(s)); item.addActionListener(equalizerUI); item.setActionCommand(s); selects.add(item); } menu.add(selects); return menu; } private JMenu createViewMenu() { JMenu menu = new JMenu(Config.getResource("PlayerUI.viewType")); menu.add(new AbstractAction(Config.getResource("PlayerUI.lrcWindow")) { public void actionPerformed(ActionEvent e) { loader.toggleLyricWindow(!config.getLrcWindow().isVisible()); } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.eqWindow")) { public void actionPerformed(ActionEvent e) { loader.toggleEqualizer(!config.getEqWindow().isVisible()); } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.plWindow")) { public void actionPerformed(ActionEvent e) { loader.togglePlaylist(!config.getPlWindow().isVisible()); } }); menu.addSeparator(); menu.add(new AbstractAction(Config.getResource("PlayerUI.fileProperty")) { public void actionPerformed(ActionEvent e) { if (currentItem != null) { SongInfoDialog info = new SongInfoDialog(config.getTopParent(), true, currentItem); info.setVisible(true); } } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.reOrder")) { public void actionPerformed(ActionEvent e) { loader.reRange(); } }); menu.add(new AbstractAction(Config.getResource("PlayerUI.alwaysOnTop")) { public void actionPerformed(ActionEvent e) { } }); return menu; } public PopupMenu createPopupMenu() { PopupMenu pm; return null; } /** * 设置按钮的位置,不管这个按钮多大 * @param ab 按钮 * @param x 中心点的X * @param y 中心点的Y */ private void setButtonLocation(AbstractButton ab, int x, int y) { int width = ab.getIcon().getIconWidth(); int height = ab.getIcon().getIconHeight(); ab.setBounds(x - width / 2, y - height / 2, width, height); this.add(ab); } /** * 加载界面 */ public void loadUI(Loader l, Config c) { this.loader = l; this.config = c; ImageBorder border = new ImageBorder(); Image bg = Util.getImage("player/main.png"); border.setImage(bg); this.setBorder(border); playlistUI = new PlayListUI(); playlistUI.setPlayerUI(this); lyricUI = new LyricUI(); lyricUI.setPlayer(this); equalizerUI = new EqualizerUI(); equalizerUI.setPlayer(this); equalizerUI.loadUI(); initUI(); addMouseVolumeListener(); loader.loaded(); thread = new Thread() { public void run() { int index = 0; while (true) { if (scrollTitle && config.isShowTitleInTaskBar()) { if (index > title.length() - 1) { index = 0; } String temp = title.substring(index) + title.substring(0, index); loader.setTitle(temp); index++; try { Thread.sleep(300); } catch (InterruptedException ex) { } } else { loader.setTitle(title); synchronized (lock) { try { lock.wait(); } catch (InterruptedException ex) { Logger.getLogger(PlayerUI.class.getName()).log(Level.SEVERE, null, ex); } } } } } }; thread.start(); } public void setShowTile(boolean b) { if (b) { synchronized (lock) { lock.notifyAll(); } } } public LyricUI getLyricUI() { return lyricUI; } public EqualizerUI getEqualizerUI() { return equalizerUI; } public PlayListUI getPlaylistUI() { return playlistUI; } public synchronized void processStateUpdated(BasicPlayerEvent event) { log.log(Level.FINE, event.toString() + "\t,Time:" + System.nanoTime() + "\t,Thread:" + Thread.currentThread()); /*-- End Of Media reached --*/ int eventState = event.getCode(); Object obj = event.getDescription(); if (eventState == BasicPlayerEvent.EOM) { title = Config.NAME; if ((playerState == PAUSE) || (playerState == PLAY)) { //如果启用了重复的策略,则分两种,一是单曲重复,一是整体重复 if (config.isRepeatEnabled()) { if (config.getRepeatStrategy() == Config.REPEAT_ALL) { //如果设了连续播放的时候间隔,则要睡这么久才能播下一首 try { Thread.sleep(config.getSequencePlayInterval() * 1000); this.nextSong(); } catch (InterruptedException ex) { Logger.getLogger(PlayerUI.class.getName()).log(Level.SEVERE, null, ex); } } else if (config.getRepeatStrategy() == Config.REPEAT_ONE) { this.play(); } } } } else if (eventState == BasicPlayerEvent.PLAYING) { int sec = (int) currentItem.getLength(); if (sec <= 0) { Long duration = (Long) audioInfo.get("duration"); if (duration != null) {//此处有必要修改ITEM的时间吗?初始化的时候是不是得到的不准确? sec = (int) (duration / 1000000); currentItem.setDuration(sec); } } timePanel.reset(sec); infoPanel.reset(currentItem); lastScrollTime = System.currentTimeMillis(); posValueJump = false; if (audioInfo.containsKey("basicplayer.sourcedataline")) { if (audioChart != null) { audioChart.setupDSP((SourceDataLine) audioInfo.get("basicplayer.sourcedataline")); audioChart.startDSP((SourceDataLine) audioInfo.get("basicplayer.sourcedataline")); } } } else if (eventState == BasicPlayerEvent.SEEKING) { posValueJump = true; } else if (eventState == BasicPlayerEvent.SEEKED) { try { player.setGain(((double) volume.getValue() / (double) volume.getMaximum())); player.setPan((float) pan.getValue() / 10.0f); } catch (BasicPlayerException e) { } } else if (eventState == BasicPlayerEvent.OPENING) { if ((obj instanceof URL) || (obj instanceof InputStream)) { showTitle(Config.getResource("title.buffering")); } } else if (eventState == BasicPlayerEvent.STOPPED) { if (audioChart != null) { audioChart.stopDSP(); audioChart.repaint(); } } changeStateTitle(eventState); } /** * 根据当前的状态改变标题的状态改变 * @param state */ private void changeStateTitle(int eventState) { switch (eventState) { case BasicPlayerEvent.EOM: case BasicPlayerEvent.STOPPED: showTitle(Config.getResource("state.stop")); currentState = Config.getResource("state.stop"); scrollTitle = false; if (currentItem != null) { title = currentItem.getFormattedName() + " - " + Config.NAME + " "; } log.log(Level.FINE, "停止:" + System.nanoTime() + "Thread:" + Thread.currentThread()); break; case BasicPlayerEvent.PLAYING: case BasicPlayerEvent.RESUMED: showTitle(Config.getResource("state.play")); currentState = Config.getResource("state.play"); title = currentItem.getFormattedName() + " - " + Config.NAME + " "; scrollTitle = true; log.log(Level.FINE, "播放:" + System.nanoTime() + "Thread:" + Thread.currentThread()); synchronized (lock) { lock.notifyAll(); } break; case BasicPlayerEvent.PAUSED: showTitle(Config.getResource("state.pause")); currentState = Config.getResource("state.pause"); title = currentItem.getFormattedName() + " - " + Config.NAME + " "; scrollTitle = false; log.log(Level.FINE, "暂停:" + System.nanoTime() + "Thread:" + Thread.currentThread()); break; } } private void showTitle(String title) { //可能是设置提示的标题 ,比如正在缓冲,正在连接什么的 if (state != null) { state.setText(title); } } 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")) { framesize = ((Integer) properties.get("audio.framesize.bytes")).intValue(); } if (bitspersample > 0) { milliseconds = (int) (1000.0f * byteslength / (samplerate * channels * (bitspersample / 8))); } else { milliseconds = (int) (1000.0f * byteslength / (samplerate * framesize)); } } } return milliseconds; } public void processProgress(int bytesread, long microseconds, byte[] pcmdata, Map properties) { int byteslength = -1; long total = -1; // Try to get time from playlist item. if (currentItem != null) { total = currentItem.getLength(); } // If it fails then try again with JavaSound SPI. if (total <= 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -