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

📄 .#playscreen.java.1.2

📁 国外的j2me播放器软件
💻 2
字号:
package no.auc.one.portableplayer.userinterface;

import javax.microedition.lcdui.*;
import no.auc.one.portableplayer.Settings;
import no.auc.one.portableplayer.communication.mediarenderer.MediaRenderer;
import no.auc.one.portableplayer.communication.mediarenderer.AVTransportService;
import no.auc.one.portableplayer.communication.mediarenderer.RenderingControlService;
import no.auc.one.portableplayer.userinterface.*;

import org.apache.log4j.*;

public class PlayScreen extends Form implements CommandListener,
                                                ItemCommandListener,
						ItemStateListener
{
    private static Logger LOG;

    private Displayable prevDisp;
    private Display disp;
    private Command goBack;
    
    private StringItem trackTitle;
    private StringItem trackArtist;
    private StringItem trackAlbum;
    private ImageItem trackArt;
    
    private ImageItem cmdPlayPause;
    private ImageItem cmdStop;
    private ImageItem cmdSkipPrev;
    private ImageItem cmdSkipNext;
    
    private Gauge audioVolume;
    
    private AVTransportService avts;
    private RenderingControlService rcs;
    
    private boolean paused;
    
    
    public PlayScreen(String title, Displayable d, Display disp) {
        super (title);
	
	paused = false;

        try {
            LOG = Logger.getLogger("PS");

            LOG.debug("Creating PlayScreen");

            this.disp = disp;
            prevDisp = d;

            goBack = new Command("Home", Command.BACK, 1);
            this.addCommand(goBack);
            this.setCommandListener(this);
	    this.setItemStateListener(this);
	    

            trackTitle = new StringItem(
                "Title: ", 
                "\n",
                Item.LAYOUT_LEFT);
            trackArtist = new StringItem(
                "Artist: ",
                "\n",
                Item.LAYOUT_LEFT);
            trackAlbum = new StringItem(
                "Album: ", 
                "\n",
                Item.LAYOUT_LEFT);
            trackArt = new ImageItem(
                "Artwork: ", 
                Image.createImage("/aml_noalpha.png"), 
                ImageItem.LAYOUT_RIGHT,
                "Agder Mobility Lab");
            
            cmdPlayPause = new ImageItem(
                "",
                Image.createImage("/play_cmd.png"),
                Item.LAYOUT_NEWLINE_BEFORE |
                Item.LAYOUT_LEFT |
                Item.BUTTON,
                "Play");
		cmdPlayPause.setDefaultCommand(new Command("Play/Pause", Command.ITEM, 1));
		cmdPlayPause.setItemCommandListener(this);
		
            cmdStop = new ImageItem(
                "",
                Image.createImage("/stop_cmd.png"),
                Item.BUTTON,
                "Stop");
		cmdStop.setDefaultCommand(new Command("Stop", Command.ITEM, 1));
		cmdStop.setItemCommandListener(this);
		
            cmdSkipPrev = new ImageItem(
                "",
                Image.createImage("/prev_cmd.png"),
                Item.BUTTON,
                "Prev");
		cmdSkipPrev.setDefaultCommand(new Command("Previous", Command.ITEM, 1));
		cmdSkipPrev.setItemCommandListener(this);
		
            cmdSkipNext = new ImageItem(
                "",
                Image.createImage("/next_cmd.png"),
                Item.BUTTON,
                "Next");
		cmdSkipNext.setDefaultCommand(new Command("Next", Command.ITEM, 1));
		cmdSkipNext.setItemCommandListener(this);
		
            audioVolume = new Gauge(
                "Volume",
                true,
                10,
                7);
            audioVolume.setLayout(audioVolume.getLayout() | Item.LAYOUT_NEWLINE_BEFORE);
            audioVolume.setItemCommandListener(this);
            
            append(trackTitle);
            append(trackAlbum);
            append(trackArtist);
            append(trackArt);
            // append some spacer here ?

            append(cmdPlayPause);
            append(cmdSkipPrev);
            append(cmdStop);
            append(cmdSkipNext);
            append(audioVolume);
        } catch (Exception e) {
            LOG.fatal("Exception while creating PlayScreen items");
            LOG.fatal(e);
            e.printStackTrace();
        }
	
	/*
	Settings s = (Settings)Settings.getInstance();
	MediaRenderer mr = (MediaRenderer)s.getCurrentMediaRenderer();
	if (mr != null) {
		avts = (AVTransportService)mr.getAVTransportService();
		rcs = (RenderingControlService)mr.getRenderingControlService();
	}
	*/
    }

    public void setSongTitle(String t) {
        trackTitle.setText("\n" + t);
    }

    public void setAlbum(String a) {
        trackAlbum.setText("\n" + a);
    }

    public void setArtist(String a) {
        trackArtist.setText("\n" + a);
    }

    public void setArt(Image i) {
        trackArt.setImage(i);
    }
    
    public void notifyPlay() {
	    
	    try {
		    cmdPlayPause.setImage(Image.createImage("/pause_cmd.png"));
	    }
	    catch (Exception e) {
		    LOG.fatal("Exception trying to create picture");
		    LOG.fatal(e);
	    }
	    
	    
	    paused = false;
    }
    
    private void actionPlay() {
	    try {
		    String resp = avts.play();
	    }
	    catch (Exception e) {
		    LOG.fatal("Exception trying to send command to renderer");
		    LOG.fatal(e);
	    }
			    
	    try {
		    cmdPlayPause.setImage(Image.createImage("/pause_cmd.png"));
	    }
	    catch (Exception e) {
		    LOG.fatal("Exception while creating Image");
		    LOG.fatal(e);
	    }
	    paused = false;
	    this.setTitle("Now playing");
    }
    private void actionPause() {
	     try {
		     String resp = avts.pause();
	     }
	     catch (Exception e) {
		     LOG.fatal("Exception trying to send command to renderer");
		     LOG.fatal(e);
	     }
			    
			    
	     try {
		     cmdPlayPause.setImage(Image.createImage("/play_cmd.png"));
	     }
	     catch (Exception e) {
		     LOG.fatal("Exception while creating Image");
		     LOG.fatal(e);
	     }
	     paused = true;
	     this.setTitle("Paused");
    }
    private void actionStop() {
	    this.setTitle("Stopped");
	    try {
		    String resp = avts.stop();
	    }
	    catch (Exception e) {
		    LOG.fatal("Exception trying to send command to renderer");
		    LOG.fatal(e);
	    }
	    
	    paused = false;
	    try {
		    cmdPlayPause.setImage(Image.createImage("/play_cmd.png"));
	    }
	    catch (Exception e) {
		    LOG.fatal("Exception while creating Image");
		    LOG.fatal(e);
	    }
	    
    }
    private void actionSkipNext() {
	    try {
		    String resp = avts.next();
	    }
	    catch (Exception e) {
		    LOG.fatal("Exception trying to send command to renderer");
		    LOG.fatal(e);
	    }
    }
    private void actionSkipPrev() {
	    try {
		    String resp = avts.previous();
	    }
	    catch (Exception e) {
		    LOG.fatal("Exception trying to send command to renderer");
		    LOG.fatal(e);
	    }
		    
    }
    private void actionSetVolume() {
	    
	    try {
		    rcs.setVolume(audioVolume.getValue()*10);
	    }
	    catch (Exception e) {
		    LOG.fatal("Exception trying to send command to renderer");
		    LOG.fatal(e);
	    }
    }

    public void commandAction(Command c, Displayable d) {
	    
	    if (goBack == c) {
		    disp.setCurrent(prevDisp);
		    System.out.println("Prev disp set...");
	    }
	    else {
		    LOG.debug("Unknown command: (" + c + ") (" + d + ")");
	    }
    }

    public void commandAction(Command c, Item i) {
	    
	    // Get AVTransportService info in contructor, then log on event
	    // listener for changed media renderer
	    
	    
	    Settings s = (Settings)Settings.getInstance();
	    MediaRenderer mr = (MediaRenderer)s.getCurrentMediaRenderer();
	    if (mr != null) {
		    avts = (AVTransportService)mr.getAVTransportService();
		    rcs = (RenderingControlService)mr.getRenderingControlService();
	    }
	    
	    if(c.getLabel().equals("Play/Pause")) {
		    
		    if (paused == true) {
			    actionPlay();
		    }
		    else {
			    actionPause();
		    }
	    }
	    else if(c.getLabel().equals("Stop")) {
		    actionStop();
	    }
	    else if(c.getLabel().equals("Previous")) {
		    actionSkipPrev();
	    }
	    else if(c.getLabel().equals("Next")) {
		    actionSkipNext();
	    }
	    else {
		    LOG.debug("Unknown Item cmd action: (" + c.getLabel() +
		    ") (" + i.getLabel() + ")");
	    }
    }
    
    public void itemStateChanged(Item i) {
	    
	    if (i == audioVolume) {
		    actionSetVolume();
            }
	    else {
		    LOG.debug("Unknown Item state changed: (" + i.getLabel() + ")");
	    }
    }
}

⌨️ 快捷键说明

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