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

📄 playerui.java

📁 java平台的图形音乐播放器
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            processPause(e.getModifiers());
        }
        // Stop
        else if (cmd.equals(PlayerActionEvent.ACSTOP))
        {
            processStop(e.getModifiers());
        }
        // Next
        else if (cmd.equals(PlayerActionEvent.ACNEXT))
        {
            processNext(e.getModifiers());
        }
        // Previous
        else if (cmd.equals(PlayerActionEvent.ACPREVIOUS))
        {
            processPrevious(e.getModifiers());
        }
    }

    /* (non-Javadoc)
     * @see javazoom.jlgui.basicplayer.BasicPlayerListener#opened(java.lang.Object, java.util.Map)
     */
    public void opened(Object stream, Map properties)
    {
        // Not in EDT.
        audioInfo = properties;
        log.debug(properties.toString());
    }

    /* (non-Javadoc)
     * @see javazoom.jlgui.basicplayer.BasicPlayerListener#stateUpdated(javazoom.jlgui.basicplayer.BasicPlayerEvent)
     */
    public void stateUpdated(final BasicPlayerEvent event)
    {
        // Not in EDT.
        processStateUpdated(event);
    }

    /* (non-Javadoc)
     * @see javazoom.jlgui.basicplayer.BasicPlayerListener#progress(int, long, byte[], java.util.Map)
     */
    public void progress(int bytesread, long microseconds, byte[] pcmdata, Map properties)
    {
        // Not in EDT.
        processProgress(bytesread, microseconds, pcmdata, properties);
    }

    /**
     * Process PREFERENCES event.
     * @param modifiers
     */
    protected void processPreferences(int modifiers)
    {
        Preferences preferences = Preferences.getInstance(this);
        preferences.setLocation(loader.getLocation().x, loader.getLocation().y);
        preferences.setSize(512, 350);
        preferences.setVisible(true);
    }

    /**
     * Process SKINS BROWSER event.
     * @param modifiers
     */
    protected void processSkinBrowser(int modifiers)
    {
        Preferences preferences = Preferences.getInstance(this);
        preferences.selectSkinBrowserPane();
        preferences.setLocation(loader.getLocation().x, loader.getLocation().y);
        preferences.setSize(512, 350);
        preferences.setVisible(true);
    }

    /**
     * Process JUMP FILE event.
     * @param modifiers
     */
    protected void processJumpToFile(int modifiers)
    {
        TagSearch ts = new TagSearch(this);
        ts.setIconImage(config.getIconParent().getImage());
        ts.setSize(400, 300);
        ts.setLocation(loader.getLocation());
        ts.display();
    }

    /**
     * Process EJECT event.
     * @param modifiers
     */
    protected void processEject(int modifiers)
    {
        if ((playerState == PLAY) || (playerState == PAUSE))
        {
            try
            {
                if (theSoundPlayer != null)
                {
                    theSoundPlayer.stop();
                }
            }
            catch (BasicPlayerException e)
            {
                log.info("Cannot stop", e);
            }
            playerState = STOP;
        }
        if ((playerState == INIT) || (playerState == STOP) || (playerState == OPEN))
        {
            PlaylistItem pli = null;
            // Local File.
            if (modifiers == MouseEvent.BUTTON1_MASK)
            {
                File[] file = FileSelector.selectFile(loader, FileSelector.OPEN, false, config.getExtensions(), ui.getResource("button.eject.filedialog.filtername"), new File(config.getLastDir()));
                if (FileSelector.getInstance().getDirectory() != null) config.setLastDir(FileSelector.getInstance().getDirectory().getPath());
                if (file != null)
                {
                    String fsFile = file[0].getName();
                    if (fsFile != null)
                    {
                        // Loads a new playlist.
                        if ((fsFile.toLowerCase().endsWith(ui.getResource("playlist.extension.m3u"))) || (fsFile.toLowerCase().endsWith(ui.getResource("playlist.extension.pls"))))
                        {
                            if (loadPlaylist(config.getLastDir() + fsFile))
                            {
                                config.setPlaylistFilename(config.getLastDir() + fsFile);
                                playlist.begin();
                                playlistUI.initPlayList();
                                setCurrentSong(playlist.getCursor());
                                playlistUI.repaint();
                            }
                        }
                        else if (fsFile.toLowerCase().endsWith(ui.getResource("skin.extension")))
                        {
                            ui.setPath(config.getLastDir() + fsFile);
                            loadSkin();
                            config.setDefaultSkin(ui.getPath());
                        }
                        else pli = new PlaylistItem(fsFile, config.getLastDir() + fsFile, -1, true);
                    }
                }
            }
            // Remote File.
            else if (modifiers == MouseEvent.BUTTON3_MASK)
            {
                UrlDialog UD = new UrlDialog(config.getTopParent(), ui.getResource("button.eject.urldialog.title"), loader.getLocation().x, loader.getLocation().y + 10, config.getLastURL());
                UD.show();
                if (UD.getFile() != null)
                {
                    showTitle(ui.getResource("title.loading"));
                    // Remote playlist ?
                    if ((UD.getURL().toLowerCase().endsWith(ui.getResource("playlist.extension.m3u"))) || (UD.getURL().toLowerCase().endsWith(ui.getResource("playlist.extension.pls"))))
                    {
                        if (loadPlaylist(UD.getURL()))
                        {
                            config.setPlaylistFilename(UD.getURL());
                            playlist.begin();
                            playlistUI.initPlayList();
                            setCurrentSong(playlist.getCursor());
                            playlistUI.repaint();
                        }
                    }
                    // Remote file or stream.
                    else
                    {
                        pli = new PlaylistItem(UD.getFile(), UD.getURL(), -1, false);
                    }
                    config.setLastURL(UD.getURL());
                }
            }
            if ((pli != null) && (playlist != null))
            {
                playlist.removeAllItems();
                playlist.appendItem(pli);
                playlist.nextCursor();
                playlistUI.initPlayList();
                setCurrentSong(pli);
                playlistUI.repaint();
            }
        }
        // Display play/time icons.
        ui.getAcPlayIcon().setIcon(2);
        ui.getAcTimeIcon().setIcon(1);
    }

    /**
     * Process PLAY event.
     * @param modifiers
     */
    protected void processPlay(int modifiers)
    {
        if (playlist.isModified()) // playlist has been modified since we were last there, must update our cursor pos etc.
        {
            PlaylistItem pli = playlist.getCursor();
            if (pli == null)
            {
                playlist.begin();
                pli = playlist.getCursor();
            }
            setCurrentSong(pli);
            playlist.setModified(false);
            playlistUI.repaint();
        }
        // Resume is paused.
        if (playerState == PAUSE)
        {
            try
            {
                theSoundPlayer.resume();
            }
            catch (BasicPlayerException e)
            {
                log.error("Cannot resume", e);
            }
            playerState = PLAY;
            ui.getAcPlayIcon().setIcon(0);
            ui.getAcTimeIcon().setIcon(0);
        }
        // Stop if playing.
        else if (playerState == PLAY)
        {
            try
            {
                theSoundPlayer.stop();
            }
            catch (BasicPlayerException e)
            {
                log.error("Cannot stop", e);
            }
            playerState = PLAY;
            secondsAmount = 0;
            ui.getAcMinuteH().setAcText("0");
            ui.getAcMinuteL().setAcText("0");
            ui.getAcSecondH().setAcText("0");
            ui.getAcSecondL().setAcText("0");
            if (currentFileOrURL != null)
            {
                try
                {
                    if (currentIsFile == true) theSoundPlayer.open(openFile(currentFileOrURL));
                    else
                    {
                        theSoundPlayer.open(new URL(currentFileOrURL));
                    }
                    theSoundPlayer.play();
                }
                catch (Exception ex)
                {
                    log.error("Cannot read file : " + currentFileOrURL, ex);
                    showMessage(ui.getResource("title.invalidfile"));
                }
            }
        }
        else if ((playerState == STOP) || (playerState == OPEN))
        {
            try
            {
                theSoundPlayer.stop();
            }
            catch (BasicPlayerException e)
            {
                log.error("Stop failed", e);
            }
            if (currentFileOrURL != null)
            {
                try
                {
                    if (currentIsFile == true) theSoundPlayer.open(openFile(currentFileOrURL));
                    else theSoundPlayer.open(new URL(currentFileOrURL));
                    theSoundPlayer.play();
                    titleText = currentSongName.toUpperCase();
                    // Get bitrate, samplingrate, channels, time in the following order :
                    // PlaylistItem, BasicPlayer (JavaSound SPI), Manual computation.
                    int bitRate = -1;
                    if (currentPlaylistItem != null) bitRate = currentPlaylistItem.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 (currentPlaylistItem != null) channels = currentPlaylistItem.getChannels();
                    if ((channels <= 0) && (audioInfo.containsKey("audio.channels"))) channels = ((Integer) audioInfo.get("audio.channels")).intValue();
                    float sampleRate = -1.0f;
                    if (currentPlaylistItem != null) sampleRate = currentPlaylistItem.getSamplerate();
                    if ((sampleRate <= 0) && (audioInfo.containsKey("audio.samplerate.hz"))) sampleRate = ((Float) audioInfo.get("audio.samplerate.hz")).floatValue();
                    long lenghtInSecond = -1L;
                    if (currentPlaylistItem != null) lenghtInSecond = currentPlaylistItem.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));
                    ui.getAcSampleRateLabel().setAcText(String.valueOf(Math.round((sampleRate / 1000))));
                    if (bitRate > 999)
                    {
                        bitRate = (int) (bitRate / 100);
                        ui.getAcBitRateLabel().setAcText(bitRate + "H");
                    }
                    else
                    {
                        ui.getAcBitRateLabel().setAcText(String.valueOf(bitRate));
                    }
                    if (channels == 2)
                    {
                        ui.getAcStereoIcon().setIcon(1);
                        ui.getAcMonoIcon().setIcon(0);
                    }
                    else if (channels == 1)
                    {
                        ui.getAcStereoIcon().setIcon(0);
                        ui.getAcMonoIcon().setIcon(1);
                    }
                    showTitle(titleText);
                    ui.getAcMinuteH().setAcText("0");
                    ui.getAcMinuteL().setAcText("0");
                    ui.getAcSecondH().setAcText("0");
                    ui.getAcSecondL().setAcText("0");
                    ui.getAcPlayIcon().setIcon(0);
                    ui.getAcTimeIcon().setIcon(0);
                }
                catch (BasicPlayerException bpe)
                {
                    log.info("Stream error :" + currentFileOrURL, bpe);
                    showMessage(ui.getResource("title.invalidfile"));
                }
                catch (MalformedURLException mue)
                {
                    log.info("Stream error :" + currentFileOrURL, mue);
                    showMessage(ui.getResource("title.invalidfile"));
                }
                // Set pan/gain.
                try
                {
                    theSoundPlayer.setGain(((double) ui.getAcVolume().getValue() / (double) ui.getAcVolume().getMaximum()));
                    theSoundPlayer.setPan((float) ui.getAcBalance().getValue() / 10.0f);
                }
                catch (BasicPlayerException e)
                {
                    log.info("Cannot set control", e);
                }

⌨️ 快捷键说明

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