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

📄 playerui.java

📁 java平台的图形音乐播放器
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                playerState = PLAY;
                log.info(titleText);
            }
        }
    }

    /**
     * Process PAUSE event.
     * @param modifiers
     */
    public void processPause(int modifiers)
    {
        if (playerState == PLAY)
        {
            try
            {
                theSoundPlayer.pause();
            }
            catch (BasicPlayerException e)
            {
                log.error("Cannot pause", e);
            }
            playerState = PAUSE;
            ui.getAcPlayIcon().setIcon(1);
            ui.getAcTimeIcon().setIcon(1);
        }
        else if (playerState == PAUSE)
        {
            try
            {
                theSoundPlayer.resume();
            }
            catch (BasicPlayerException e)
            {
                log.info("Cannot resume", e);
            }
            playerState = PLAY;
            ui.getAcPlayIcon().setIcon(0);
            ui.getAcTimeIcon().setIcon(0);
        }
    }

    /**
     * Process STOP event. 
     * @param modifiers
     */
    public void processStop(int modifiers)
    {
        if ((playerState == PAUSE) || (playerState == PLAY))
        {
            try
            {
                theSoundPlayer.stop();
            }
            catch (BasicPlayerException e)
            {
                log.info("Cannot stop", e);
            }
            playerState = STOP;
            secondsAmount = 0;
            ui.getAcPosBar().setValue(0);
            ui.getAcPlayIcon().setIcon(2);
            ui.getAcTimeIcon().setIcon(1);
        }
    }

    /**
     * Process NEXT event.
     * @param modifiers
     */
    public void processNext(int modifiers)
    {
        // Try to get next song from the playlist
        playlist.nextCursor();
        playlistUI.nextCursor();
        PlaylistItem pli = playlist.getCursor();
        setCurrentSong(pli);
    }

    /**
     * Process PREVIOUS event.
     * @param modifiers
     */
    public void processPrevious(int modifiers)
    {
        // Try to get previous song from the playlist
        playlist.previousCursor();
        playlistUI.nextCursor();
        PlaylistItem pli = playlist.getCursor();
        setCurrentSong(pli);
    }

    /**
     * Process STATEUPDATED event.
     * @param event
     */
    public void processStateUpdated(BasicPlayerEvent event)
    {
        log.debug("Player:" + event + " (EDT=" + SwingUtilities.isEventDispatchThread() + ")");
        /*-- End Of Media reached --*/
        int state = event.getCode();
        Object obj = event.getDescription();
        if (state == BasicPlayerEvent.EOM)
        {
            if ((playerState == PAUSE) || (playerState == PLAY))
            {
                playlist.nextCursor();
                playlistUI.nextCursor();
                PlaylistItem pli = playlist.getCursor();
                setCurrentSong(pli);
            }
        }
        else if (state == BasicPlayerEvent.PLAYING)
        {
            lastScrollTime = System.currentTimeMillis();
            posValueJump = false;
            if (audioInfo.containsKey("basicplayer.sourcedataline"))
            {
                if (ui.getAcAnalyzer() != null)
                {
                    ui.getAcAnalyzer().setupDSP((SourceDataLine) audioInfo.get("basicplayer.sourcedataline"));
                    ui.getAcAnalyzer().startDSP((SourceDataLine) audioInfo.get("basicplayer.sourcedataline"));
                }
            }
        }
        else if (state == BasicPlayerEvent.SEEKING)
        {
            posValueJump = true;
        }
        else if (state == BasicPlayerEvent.SEEKED)
        {
            try
            {
                theSoundPlayer.setGain(((double) ui.getAcVolume().getValue() / (double) ui.getAcVolume().getMaximum()));
                theSoundPlayer.setPan((float) ui.getAcBalance().getValue() / 10.0f);
            }
            catch (BasicPlayerException e)
            {
                log.debug(e);
            }            
        }
        else if (state == BasicPlayerEvent.OPENING)
        {
            if ((obj instanceof URL) || (obj instanceof InputStream))
            {
                showTitle(ui.getResource("title.buffering"));
            }
        }
        else if (state == BasicPlayerEvent.STOPPED)
        {
            if (ui.getAcAnalyzer() != null)
            {
                ui.getAcAnalyzer().stopDSP();
                ui.getAcAnalyzer().repaint();
            }
        }
    }

    /**
     * Process PROGRESS event.
     * @param bytesread
     * @param microseconds
     * @param pcmdata
     * @param properties
     */
    public void processProgress(int bytesread, long microseconds, byte[] pcmdata, Map properties)
    {
        //log.debug("Player: Progress (EDT="+SwingUtilities.isEventDispatchThread()+")");
        int byteslength = -1;
        long total = -1;
        // Try to get time from playlist item.
        if (currentPlaylistItem != null) total = currentPlaylistItem.getLength();
        // If it fails then try again with JavaSound SPI.
        if (total <= 0) total = (long) Math.round(getTimeLengthEstimation(audioInfo) / 1000);
        // 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 (ui.getAcAnalyzer() != null) ui.getAcAnalyzer().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;
        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 (currentPlaylistItem != null)
                        {
                            String sTitle = " (" + currentPlaylistItem.getFormattedDisplayName() + ")";
                            if (!currentPlaylistItem.getFormattedName().equals(shoutTitle + sTitle))
                            {
                                currentPlaylistItem.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);
        /*-- Display elapsed time --*/
        int secondD = 0, second = 0, minuteD = 0, minute = 0;
        int seconds = (int) secondsAmount;
        int minutes = (int) Math.floor(seconds / 60);
        int hours = (int) Math.floor(minutes / 60);
        minutes = minutes - hours * 60;
        seconds = seconds - minutes * 60 - hours * 3600;
        if (seconds < 10)
        {
            secondD = 0;
            second = seconds;
        }
        else
        {
            secondD = ((int) seconds / 10);
            second = ((int) (seconds - (((int) seconds / 10)) * 10));
        }
        if (minutes < 10)
        {
            minuteD = 0;
            minute = minutes;
        }
        else
        {
            minuteD = ((int) minutes / 10);
            minute = ((int) (minutes - (((int) minutes / 10)) * 10));
        }
        ui.getAcMinuteH().setAcText(String.valueOf(minuteD));
        ui.getAcMinuteL().setAcText(String.valueOf(minute));
        ui.getAcSecondH().setAcText(String.valueOf(secondD));
        ui.getAcSecondL().setAcText(String.valueOf(second));
        // Update PosBar location.
        if (total != 0)
        {
            if (posValueJump == false)
            {
                int posValue = ((int) Math.round(secondsAmount * Skin.POSBARMAX / total));
                ui.getAcPosBar().setValue(posValue);
            }
        }
        else ui.getAcPosBar().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
                ui.getAcTitleLabel().setAcText(titleScrollLabel[scrollIndex]);
            }
        }
    }

    /**
     * Process seek feature.
     * @param rate
     */
    protected void processSeek(double rate)
    {
        try
        {
            if ((audioInfo != null) && (audioInfo.containsKey("audio.type")))
            {
                String type = (String) audioInfo.get("audio.type");
                // Seek support for MP3.
                if ((type.equalsIgnoreCase("mp3")) && (audioInfo.containsKey("audio.length.bytes")))
                {
                    long skipBytes = (long) Math.round(((Integer) audioInfo.get("audio.length.bytes")).intValue() * rate);
                    log.debug("Seek value (MP3) : " + skipBytes);
                    theSoundPlayer.seek(skipBytes);
                }
                // Seek support for WAV.
                else if ((type.equalsIgnoreCase("wave")) && (audioInfo.containsKey("audio.length.bytes")))
                {
                    long skipBytes = (long) Math.round(((Integer) audioInfo.get("audio.length.bytes")).intValue() * rate);
                    log.debug("Seek value (WAVE) : " + skipBytes);
                    theSoundPlayer.seek(skipBytes);
                }
                else posValueJump = false;
            }
            else posValueJump = false;
        }
        catch (BasicPlayerException ioe)
        {
            log.error("Cannot skip", ioe);
            posValueJump = false;
        }
    }

    /**
     * Process Drag&Drop
     * @param data
     */
    public void processDnD(Object data)
    {
        log.debug("Player DnD");
        // Looking for files to drop.
        if (data instanceof List)
        {
            List al = (List) data;
            if ((al != null) && (al.size() > 0))
            {

⌨️ 快捷键说明

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