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

📄 player.java

📁 一个J2EE 做的 网上图书销售管理系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        add(acPause);
        acPause.setActionCommand("Pause");
        acPause.addActionListener(this);

        acStop =  new activeComponent(releasedImage[3],pressedImage[3],AWTEvent.MOUSE_EVENT_MASK);
        acStop.setLocation(panelLocation[l++],panelLocation[l++]);
        add(acStop);
        acStop.setActionCommand("Stop");
        acStop.addActionListener(this);

        acNext =  new activeComponent(releasedImage[4],pressedImage[4],AWTEvent.MOUSE_EVENT_MASK);
        acNext.setLocation(panelLocation[l++],panelLocation[l++]);
        add(acNext);
        acNext.setActionCommand("Next");
        acNext.addActionListener(this);

        acEject =  new activeComponent(releasedImage[5],pressedImage[5],AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
        acEject.setLocation(panelLocation[l++],panelLocation[l++]);
        add(acEject);
        acEject.setActionCommand("Eject");
        acEject.addActionListener(this);
    }

    /**
     * Instantiate Title Panel with activeComponent.
     * Add them to window and ActionListener.
     */
    private void setTitleBarPanel()
    {
        int l = 0;
        acTitleBar = new activeComponent(releasedTitleIm[0],pressedTitleIm[0],AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);
        acTitleBar.setLocation(titleBarLocation[l++],titleBarLocation[l++]);
        add(acTitleBar);
        acTitleBar.setActionCommand("TitleBar");
        acTitleBar.addActionListener(this);
    }

    /**
     * Instantiate Exit Panel with activeComponent.
     * Add them to window and ActionListener.
     */
    private void setExitPanel()
    {
        int l = 0;
        acExit = new activeComponent(releasedExitIm[0],pressedExitIm[0],AWTEvent.MOUSE_EVENT_MASK);
        acExit.setLocation(exitLocation[l++],exitLocation[l++]);
        add(acExit);
        acExit.setActionCommand("Exit");
        acExit.addActionListener(this);
    }

    /**
     * Instantiate Volume/Balance Panel with activeComponent.
     * Add them to window and ActionListener.
     */
    private void setVolumePanel()
    {
        int l = 0;
        acVolume = new activeComponent(releasedVolumeImage[0],pressedVolumeImage[0],AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);
        acVolume.setLocation(volumeLocation[l++],volumeLocation[l++]);
        add(acVolume);
        acVolume.setActionCommand("Volume");
        acVolume.addActionListener(this);
        for (int k=0;k<volumeImage.length;k++)
        {
            volumeImage[k] = (new taftb(fakeIndex, imVolume, 68, 13, 2, ""+fakeIndex.charAt(k))).getBanner();
        }
        offScreenGraphics.drawImage(volumeImage[(int)Math.round(((double)gainValue / (double)maxGain)*(volumeImage.length-1))], volumeBarLocation[0], volumeBarLocation[1], this);

		l = 0;
        acBalance = new activeComponent(releasedVolumeImage[0],pressedVolumeImage[0],AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);
        acBalance.setLocation(balanceLocation[l++],balanceLocation[l++]);
        add(acBalance);
        acBalance.setActionCommand("Balance");
        acBalance.addActionListener(this);
		balanceImage[0] = (new taftb("a", imVolume, deltaBalance+14, 13, 2, "a")).getBanner();
		offScreenGraphics.drawImage(balanceImage[0], balanceBarLocation[0], balanceBarLocation[1], this);

    }

    /**
     * Instantiate PosBar Panel with activeComponent.
     * Add them to window and ActionListener.
     */
    private void setPosBarPanel()
    {
        int l = 0;
        acPosBar = new activeComponent(releasedPosIm[0],pressedPosIm[0],AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);
        acPosBar.setLocation(posBarLocation[l++],posBarLocation[l++]);
        add(acPosBar);
        acPosBar.setActionCommand("Seek");
        acPosBar.addActionListener(this);
        remove(acPosBar);
    }

	/**
	 * Sets the current song to play and start playing if needed.
	 */
	private void setCurrentSong(PlaylistItem pli)
	{
		int playerStateMem = playerState;
        if ( (playerState == PAUSE) || (playerState == PLAY) )
        {
			theSoundPlayer.stopPlayback();
            playerState = STOP;
            secondsAmount = 0;
            acPosBar.setLocation(posBarBounds[0],posBarLocation[1]);
            offScreenGraphics.drawImage(iconsImage[2], iconsLocation[0], iconsLocation[1], this);
			offScreenGraphics.drawImage(iconsImage[4], iconsLocation[2], iconsLocation[3], this);
        }
        playerState = OPEN;
		if (pli != null)
		{
			currentSongName = pli.getName();
			currentFileOrURL = pli.getLocation();
			currentIsFile = pli.isFile();
		}
		else
		{
			currentSongName = TITLETEXT;
			currentFileOrURL = null;
			currentIsFile = false;
		}
		if (currentIsFile == true)
		{
			add(acPosBar);
		}
		else
		{
			config.setLastURL(currentFileOrURL);
			remove(acPosBar);
		}
        titleText = currentSongName.toUpperCase();
        titleImage = (new taftb(fontIndex, imText, fontWidth, fontHeight, 0, titleText)).getBanner(0,0,155,6);
        offScreenGraphics.drawImage(clearImage, titleLocation[0], titleLocation[1], this);
        offScreenGraphics.drawImage(titleImage, titleLocation[0], titleLocation[1], this);
        offScreenGraphics.drawImage(sampleRateClearImage, sampleRateLocation[0], sampleRateLocation[1], this);
        offScreenGraphics.drawImage(bitsRateClearImage,bitsRateLocation[0], bitsRateLocation[1], this);
        offScreenGraphics.drawImage(passiveModeImage[0], stereoLocation[0], stereoLocation[1], this);
        offScreenGraphics.drawImage(passiveModeImage[1], monoLocation[0], monoLocation[1], this);
        offScreenGraphics.drawImage(timeImage[0], minuteDLocation[0], minuteDLocation[1], this);
        offScreenGraphics.drawImage(timeImage[0], minuteLocation[0], minuteLocation[1], this);
        offScreenGraphics.drawImage(timeImage[0], secondDLocation[0], secondDLocation[1], this);
        offScreenGraphics.drawImage(timeImage[0], secondLocation[0], secondLocation[1], this);
        repaint();
        // Start playing if needed.
        if ((playerStateMem == PLAY) || (playerStateMem == PAUSE))
        {
			acPlay.fireEvent();
		}
	}

    /*-----------------------------------------*/
    /*--    BasicPlayerListener Interface    --*/
    /*-----------------------------------------*/

	/**
	 * BasicPlayerListener implementation.
	 * It manages "elapsed time" event.
	 */
    public void updateCursor(int secondsAmount, int total)
    {
        /*-- Display elapsed time --*/
        //secondsAmount++;
        int      secondD,second,minuteD,minute;
        int      minutes = (int) (secondsAmount/60);
        int      seconds = (int) (secondsAmount - (minutes*60));
        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));
        }
        // Update PosBar location.
        if (total != 0)
        {
			if (FirstPosBarDrag == true)
        	{
        		posBarLocation[0] = ((int) Math.round(secondsAmount*deltaPosBar/total)) + posBarBounds[0];
        		acPosBar.setLocation(posBarLocation[0],posBarLocation[1]);
			}
		}
		else posBarLocation[0] = posBarBounds[0];
        offScreenGraphics.drawImage(timeImage[minuteD], minuteDLocation[0], minuteDLocation[1], this);
        offScreenGraphics.drawImage(timeImage[minute], minuteLocation[0], minuteLocation[1], this);
        offScreenGraphics.drawImage(timeImage[secondD], secondDLocation[0], secondDLocation[1], this);
        offScreenGraphics.drawImage(timeImage[second], secondLocation[0], secondLocation[1], this);
        repaint();
    }

	/**
	 * BasicPlayerListener implementation.
	 * It manages End Of Media event.
	 */
	public void updateMediaState(String state)
	{
        /*-- End Of Media reached --*/
		if (state.equals("EOM"))
		{
	        if ( (playerState == PAUSE) || (playerState == PLAY) )
	        {
	           	playlist.nextCursor();
	           	PlaylistItem pli = playlist.getCursor();
				this.setCurrentSong(pli);
			}
		}
	}


	/**
	 * BasicPlayerListener implementation.
	 */
	public void updateMediaData(byte[] data)
	{
		// Spectrum analyzer could take place here
	}


    /**
     * Manages events.
     */
    public void actionPerformed( ActionEvent e )
    {
        /*------------------------------------*/
        /*--        Interact on Seek        --*/
        /*------------------------------------*/
        if (e.getActionCommand().equals("Seek"))
        {
            if (acPosBar.isMousePressed() == false)
			{
				FirstPosBarDrag = true;
				try
				{
					theSoundPlayer.setSeek(posValue);
				} catch (IOException ioe)
				  {
					  ioe.printStackTrace();
				  }
				repaint();
			}
            else
            {
        		int DeltaX = 0;
	        	if (FirstPosBarDrag == false)
	        	{
	    	    	DeltaX = acPosBar.getMouseX() - XPosBarDrag;
	    		    XPosBarDrag = acPosBar.getMouseX() - DeltaX;
	    		    if (posBarLocation[0]+DeltaX < posBarBounds[0]) posBarLocation[0] = posBarBounds[0];
	    		    else if (posBarLocation[0]+DeltaX  > posBarBounds[1]) posBarLocation[0] = posBarBounds[1];
	    		    else posBarLocation[0] = posBarLocation[0] + DeltaX;
		    	    acPosBar.setLocation(posBarLocation[0],posBarLocation[1]);
                    double a = (maxPos-minPos)/(posBarBounds[1] - posBarBounds[0]);
                    posValue = (a*(posBarLocation[0] - posBarBounds[0]) + minPos);
		        }
    		    else
	    	    {
		        	FirstPosBarDrag = false;
		        	XPosBarDrag = acPosBar.getMouseX();
	    	    }
	    	}
        }

        /*------------------------------------*/
        /*--       Interact on Volume       --*/
        /*------------------------------------*/
        else if (e.getActionCommand().equals("Volume"))
        {
            if (acVolume.isMousePressed() == false)
			{
				FirstVolumeDrag = true;
		        offScreenGraphics.drawImage(clearImage, titleLocation[0], titleLocation[1], this);
	            offScreenGraphics.drawImage(titleImage, titleLocation[0], titleLocation[1], this);
				repaint();
			}
            else
            {
        		int DeltaX = 0;
	        	if (FirstVolumeDrag == false)
	        	{
	    	    	DeltaX = acVolume.getMouseX() - XVolumeDrag;
	    		    XVolumeDrag = acVolume.getMouseX() - DeltaX;
	    		    if (volumeLocation[0]+DeltaX < volumeBounds[0]) volumeLocation[0] = volumeBounds[0];
	    		    else if (volumeLocation[0]+DeltaX  > volumeBounds[1]) volumeLocation[0] = volumeBounds[1];
	    		    else volumeLocation[0] = volumeLocation[0] + DeltaX;
		    	    acVolume.setLocation(volumeLocation[0],volumeLocation[1]);
                    double a = (maxGain-minGain)/(volumeBounds[1] - volumeBounds[0]);
                    gainValue = (int) (a*(volumeLocation[0] - volumeBounds[0]) + minGain);
		    		if (gainValue == 0) theSoundPlayer.setGain( 0 );
			        else theSoundPlayer.setGain(((double)gainValue / (double)maxGain) );
                    String volumeText = "VOLUME: "+(int) Math.round((100/(volumeBounds[1] - volumeBounds[0]))*(volumeLocation[0] - volumeBounds[0]))+"%";
                    Image volImage = (new taftb(fontIndex, imText, fontWidth, fontHeight, 0, volumeText)).getBanner();
                    offScreenGraphics.drawImage(volumeImage[(int)Math.round(((double)gainValue / (double)maxGain)*(volumeImage.length-1))], volumeBarLocation[0], volumeBarLocation[1], this);
                    offScreenGraphics.drawImage(clearImage, titleLocation[0], titleLocation[1], this);
                    offScreenGraphics.drawImage(volImage, titleLocation[0], titleLocation[1], this);
		        }
    		    else
	    	    {
		        	FirstVolumeDrag = false;
		        	XVolumeDrag = acVolume.getMouseX();
	    	    }
	    	}
        }

        /*------------------------------------*/
        /*--       Interact on Balance       --*/
        /*------------------------------------*/
        else if (e.getActionCommand().equals("Balance"))
        {
            if (acBalance.isMousePressed() == false)
			{
				FirstBalanceDrag = true;
				offScreenGraphics.drawImage(clearImage, titleLocation[0], titleLocation[1], this);
             	offScreenGraphics.drawImage(titleImage, titleLocation[0], titleLocation[1], this);
				repaint();
			}
            else
            {
        		int DeltaX = 0;
	        	if (FirstBalanceDrag == false)
	        	{
	    	    	DeltaX = acBalance.getMouseX() - XBalanceDrag;
	    		    XBalanceDrag = acBalance.getMouseX() - DeltaX;
	    		    if (balanceLocation[0]+DeltaX < balanceBounds[0]) balanceLocation[0] = balanceBounds[0];
	    		    else if (balanceLocation[0]+DeltaX  > balanceBounds[1]) balanceLocation[0] = balanceBounds[1];
	    		    else balanceLocation[0] = balanceLocation[0] + DeltaX;
		    	    acBalance.setLocation(balanceLocation[0],balanceLocation[1]);
                    double a = (maxBalance-minBalance)/(balanceBounds[1] - balanceBounds[0]);
                    balanceValue = (a*(balanceLocation[0] - balanceBounds[0]) + minBalance);
		    		theSoundPlayer.setPan((float)balanceValue);
                    String balanceText = "BALANCE: " + (int) Math.abs(balanceValue*100) + "%";
					if (balanceValue > 0) balanceText = balanceText + " RIGHT";
					else if (balanceValue < 0)  balanceText = balanceText + " LEFT";
					else  balanceText = "BALANCE: CENTER";
                    Image balImage = (new taftb(fontIndex, imText, fontWidth, fontHeight, 0, balanceText)).getBanner();
                    offScreenGraphics.drawImage(balanceImage[0], balanceBarLocation[0], balanceBarLocation[1], this);
                    offScreenGraphics.drawImage(clearImage, titleLocation[0], titleLocation[1], this);
                    offScreenGraphics.drawImage(balImage, titleLocation[0], titleLocation[1], this);
		        }
    		    else
	    	    {
		        	FirstBalanceDrag = false;
		        	XBalanceDrag = acBalance.getMouseX();
	    	    }
	    	}
        }

        /*------------------------------------*/
        /*-- Select Filename or URL to load --*/
        /*------------------------------------*/
        else if (e.getActionCommand().equals("Eject"))
        {
            if ((playerState == PLAY) || (playerState == PAUSE))
            {
                theSoundPlayer.stopPlayback();
                playerState = STOP;
            }

⌨️ 快捷键说明

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