⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playerui.java

📁 java+eclipse做的TTPlayer
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * 在这里显示一些常用的东西     * 比如改变标题,以及时间清0,还有,歌曲信息的改变     * 比如比特率,单双声道等全部重置,因为一首新的歌曲要开始了     * 即使不开始,在不播的时候清除这些也是应该的     * @param titleText     */    public void showMessage(String titleText) {    }    /**     * 处理播放的请求,这下就要分很多种情况了,哈哈     * @param modifiers     */    protected void processPlay(int modifiers) {        //先检查播放列表有没有改变,改变了就要检查一下了        //因为下一个下标或者当前的下标并不一定有效了,有可能        //删除了一些列表项        log.log(Level.INFO, "processPlay....... ");        // playlist has been modified since we were last there, must update our cursor pos etc.        if (playlist.isModified()) {            PlayListItem pli = playlist.getCursor();            log.log(Level.INFO, "播放列表改了..." + pli);            //如果当前的列表项已经为空了,则从头开始播了            if (pli == null) {                playlist.begin();                pli = playlist.getCursor();            }            setCurrentSong(pli);            playlist.setModified(false);            playlistUI.repaint();        }        //如果当前的状态是暂停,则马上恢复        if (playerState == PAUSE) {            try {                player.resume();            } catch (BasicPlayerException e) {            }            playerState = PLAY;        //更改播放的图标,让暂停的图标变成正在播放的图标        //时间的图标也要变一下//            skin.getAcPlayIcon().setIcon(0);//            skin.getAcTimeIcon().setIcon(0);        } //如果正在播放的话,则先停止它,再从头播放,这样更合普通使用习惯        else if (playerState == PLAY) {            try {                player.stop();            } catch (BasicPlayerException e) {            }            playerState = PLAY;            secondsAmount = 0;            timePanel.reset();            //重置当前显示时间//            skin.getAcMinuteH().setAcText("0");//            skin.getAcMinuteL().setAcText("0");//            skin.getAcSecondH().setAcText("0");//            skin.getAcSecondL().setAcText("0");            if (currentFileOrURL != null) {                try {                    if (currentIsFile == true) {                        player.open(new File(currentFileOrURL));                    } else {                        player.open(new URL(currentFileOrURL));                    }                    player.play();                } catch (Exception ex) {                    showMessage(Config.getResource("title.invalidfile"));                }            }//如果状态是停止或者状态是已经打开文件了,则先停止,再播放        //在这种播放的状态下,需要重新读取歌曲文件的一些信息,比如比特率,是否单双声道等等        } else if ((playerState == STOP) || (playerState == OPEN)) {            try {                player.stop();            } catch (BasicPlayerException e) {            }            if (currentFileOrURL != null) {                try {                    if (currentIsFile == true) {                        player.open(new File(currentFileOrURL));                    } else {                        player.open(new URL(currentFileOrURL));                    }                    player.play();                    lyric = new Lyric(currentItem);                    lyricUI.setLyric(lyric);                    titleText = currentSongName.toUpperCase();                    // Get bitrate, samplingrate, channels, time in the following order :                    // PlaylistItem, BasicPlayer (JavaSound SPI), Manual computation.                    int bitRate = -1;                    if (currentItem != null) {                        bitRate = currentItem.getBitrate();                    }                    if ((bitRate <= 0) && (audioInfo.containsKey("bitrate"))) {                        bitRate = ((Integer) audioInfo.get("bitrate")).intValue();                    }                    if ((bitRate <= 0) && (audioInfo.containsKey("audio.framerate.fps")) && (audioInfo.containsKey("audio.framesize.bytes"))) {                        float FR = ((Float) audioInfo.get("audio.framerate.fps")).floatValue();                        int FS = ((Integer) audioInfo.get("audio.framesize.bytes")).intValue();                        bitRate = Math.round(FS * FR * 8);                    }                    int channels = -1;                    if (currentItem != null) {                        channels = currentItem.getChannels();                    }                    if ((channels <= 0) && (audioInfo.containsKey("audio.channels"))) {                        channels = ((Integer) audioInfo.get("audio.channels")).intValue();                    }                    float sampleRate = -1.0f;                    if (currentItem != null) {                        sampleRate = currentItem.getSamplerate();                    }                    if ((sampleRate <= 0) && (audioInfo.containsKey("audio.samplerate.hz"))) {                        sampleRate = ((Float) audioInfo.get("audio.samplerate.hz")).floatValue();                    }                    long lenghtInSecond = -1L;                    if (currentItem != null) {                        lenghtInSecond = currentItem.getLength();                    }                    if ((lenghtInSecond <= 0) && (audioInfo.containsKey("duration"))) {                        lenghtInSecond = ((Long) audioInfo.get("duration")).longValue() / 1000000;                    }                    if ((lenghtInSecond <= 0) && (audioInfo.containsKey("audio.length.bytes"))) {                        // Try to compute time length.                        lenghtInSecond = (long) Math.round(getTimeLengthEstimation(audioInfo) / 1000);                        if (lenghtInSecond > 0) {                            int minutes = (int) Math.floor(lenghtInSecond / 60);                            int hours = (int) Math.floor(minutes / 60);                            minutes = minutes - hours * 60;                            int seconds = (int) (lenghtInSecond - minutes * 60 - hours * 3600);                            if (seconds >= 10) {                                titleText = "(" + minutes + ":" + seconds + ") " + titleText;                            } else {                                titleText = "(" + minutes + ":0" + seconds + ") " + titleText;                            }                        }                    }                    bitRate = Math.round((bitRate / 1000));                    currentItem.setSampled(String.valueOf(Math.round((sampleRate / 1000))) + "kHz");                    if (bitRate > 999) {                        bitRate = (bitRate / 100);                        currentItem.setBitRate(bitRate + "Hkbps");                    } else {                        currentItem.setBitRate(String.valueOf(bitRate) + "kbps");                    }                    if (channels == 2) {                        currentItem.setChannels(Config.getResource("songinfo.channel.stereo"));                    } else if (channels == 1) {                        currentItem.setChannels(Config.getResource("songinfo.channel.mono"));                    }//                    showTitle(titleText);//                    skin.getAcMinuteH().setAcText("0");//                    skin.getAcMinuteL().setAcText("0");//                    skin.getAcSecondH().setAcText("0");//                    skin.getAcSecondL().setAcText("0");                //把播放按钮的图片变成可以按暂停//                    skin.getAcPlayIcon().setIcon(0);//                    skin.getAcTimeIcon().setIcon(0);                } catch (BasicPlayerException bpe) {                    showMessage(Config.getResource("title.invalidfile"));                } catch (MalformedURLException mue) {                    showMessage(Config.getResource("title.invalidfile"));                }                // Set pan/gain.                //因为是重新读取的,所以要设置声音和声道                try {                    //要看是不是静音,静听就不用设声音了                    if (config.isMute()) {                        player.setGain(0);                    } else {                        player.setGain(((double) volume.getValue() / (double) volume.getMaximum()));                    }                    player.setPan((float) pan.getValue() / 10.0f);                } catch (BasicPlayerException e) {                }                playerState = PLAY;            }        }        changePlayPauseState(playerState);        pos.setEnabled(true);        if (!isSeeked && config.isAutoPlayWhenStart() && config.isMaintainLastPlay()) {            isSeeked = true;            processSeek(lastRate);        }    }    /**     *根据播放或者暂停来改变那个按钮的图标     * @param state 状态     */    private void changePlayPauseState(int state) {        if (state == PLAY) {            play.setActionCommand(Config.PAUSE);            play.setIcon(new ImageIcon(pauseImgs[0]));            play.setRolloverIcon(new ImageIcon(pauseImgs[1]));            play.setPressedIcon(new ImageIcon(pauseImgs[2]));        } else if (state == PAUSE || state == STOP) {            play.setActionCommand(Config.PLAY);            play.setIcon(new ImageIcon(playImgs[0]));            play.setRolloverIcon(new ImageIcon(playImgs[1]));            play.setPressedIcon(new ImageIcon(playImgs[2]));        }    }    public void processPause(int modifiers) {        if (playerState == PLAY) {            try {                player.pause();            } catch (BasicPlayerException e) {            }            playerState = PAUSE;            changePlayPauseState(playerState);        //改变播放按钮的图片,让它显示可播放//            skin.getAcPlayIcon().setIcon(1);//            skin.getAcTimeIcon().setIcon(1);        } else if (playerState == PAUSE) {            try {                player.resume();            } catch (BasicPlayerException e) {            }            playerState = PLAY;            changePlayPauseState(playerState);        //改变播放按钮的图片,让它显示可播放//            skin.getAcPlayIcon().setIcon(0);//            skin.getAcTimeIcon().setIcon(0);        }    }    public void processNext(int modifiers) {        // Try to get next song from the playlist        playlist.nextCursor();        //这里是只要重绘还是还要显式地调用nextCursor()?        playlistUI.repaint();        PlayListItem pli = playlist.getCursor();        setCurrentSong(pli);    }    public void processPrevious(int modifiers) {        // Try to get previous song from the playlist        playlist.previousCursor();        playlistUI.repaint();        PlayListItem pli = playlist.getCursor();        setCurrentSong(pli);    }    public void processActionEvent(ActionEvent e) {        String cmd = e.getActionCommand();        // Preferences.        if (false) {        } else if (cmd.equalsIgnoreCase(Config.EQ_ON)) {            loader.toggleEqualizer(true);            eq.setActionCommand(Config.EQ_OFF);        } else if (cmd.equalsIgnoreCase(Config.EQ_OFF)) {            loader.toggleEqualizer(false);            eq.setActionCommand(Config.EQ_ON);        } else if (cmd.equalsIgnoreCase(Config.PL_ON)) {            loader.togglePlaylist(true);            pl.setActionCommand(Config.PL_OFF);        } else if (cmd.equalsIgnoreCase(Config.PL_OFF)) {            loader.togglePlaylist(false);            pl.setActionCommand(Config.PL_ON);        } else if (cmd.equals(Config.LRC_ON)) {            loader.toggleLyricWindow(true);            lrc.setActionCommand(Config.LRC_OFF);        } else if (cmd.equals(Config.LRC_OFF)) {            loader.toggleLyricWindow(false);            lrc.setActionCommand(Config.LRC_ON);        } else if (cmd.equals(Config.VOL_ON)) {            config.setMute(false);            changeSpeakerState();        } else if (cmd.equals(Config.VOL_OFF)) {            config.setMute(true);            changeSpeakerState();        } //        if (cmd.equalsIgnoreCase(PlayerActionEvent.MIPREFERENCES)) {        //            processPreferences(e.getModifiers());        //        } // Skin browser        //        else if (cmd.equals(PlayerActionEvent.MISKINBROWSER)) {        //            processSkinBrowser(e.getModifiers());        //        } // Jump to file        //        else if (cmd.equals(PlayerActionEvent.MIJUMPFILE)) {        //            processJumpToFile(e.getModifiers());        //        } // Stop        else if (cmd.equals(Config.STOP)) {            processStop(e.getModifiers());        } // Load skin        //        else if (e.getActionCommand().equals(PlayerActionEvent.MILOADSKIN)) {        //            File[] file = FileSelector.selectFile(loader, FileSelector.OPEN, false, skin.getResource("skin.extension"), skin.getResource("loadskin.dialog.filtername"), new File(config.getLastDir()));        //            if (FileSelector.getInstance().getDirectory() != null) {        //                config.setLastDir(FileSelector.getInstance().getDirectory().getPath());        //            }        //            if (file != null) {        //                String fsFile = file[0].getName();        //                skin.setPath(config.getLastDir() + fsFile);        //                loadSkin();        //                config.setDefaultSkin(skin.getPath());        //            }        //        } // Shuffle        //        else if (cmd.equals(PlayerActionEvent.ACSHUFFLE)) {        //            if (skin.getAcShuffle().isSelected()) {        //                config.setShuffleEnabled(true);        //                if (playlist != null) {        //                    playlist.shuffle();        //                    playlistUI.initPlayList();        //                    // Play from the top        //                    PlaylistItem pli = playlist.getCursor();        //                    setCurrentSong(pli);        //                }        //            } else {        //                config.setShuffleEnabled(false);        //            }        //        } // Repeat        //        else if (cmd.equals(PlayerActionEvent.ACREPEAT)) {        //            if (skin.getAcRepeat().isSelected()) {        //                config.setRepeatEnabled(true);        //            } else {        //                config.setRepeatEnabled(false);        //            }        //        } // Play file        //        else if (cmd.equals(PlayerActionEvent.MIPLAYFILE)) {        //            processEject(MouseEvent.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -