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

📄 simpleplayerform.java

📁 程序使用 MMAPI 来回放音调、音频文件和视频文件的一组 MIDlet。 需要:MIDP 2.0、Mobile Media API 1.1 (MMAPI 1.1)
💻 JAVA
字号:
/* * @(#)SimplePlayerForm.java	1.5 03/03/03 * * Copyright (c) 2004 Sun Microsystems, Inc.  All rights reserved. * Use is subject to license terms */package example.mmademo;import javax.microedition.lcdui.*;import javax.microedition.media.*;import javax.microedition.media.control.*;import java.io.InputStream;/** * MMA player main window for media files, implemented as a Form * * @author Florian Bomers * @version 1.8 */public class SimplePlayerForm extends Form implements SimplePlayerGUI.Parent, Utils.ContentHandler, Runnable {        private SimplePlayerGUI gui; // default: null    private Utils.BreadCrumbTrail parent;        private ImageItem iiLogo;    private StringItem siFileTitle;    private StringItem siTime;    private StringItem siRate;    private StringItem siKaraoke;    private StringItem siFeedback;    private StringItem siStatus;    private Object guiItem;        private boolean karaokeShowing;        private static int maxKaraokeLines = 2;        private static void debugOut(String s) {	Utils.debugOut("SimplePlayerForm: "+s);    }    public SimplePlayerForm(String title, Utils.BreadCrumbTrail parent) {    	this(title, null, parent);    }    public SimplePlayerForm(String title, SimplePlayerGUI spg, Utils.BreadCrumbTrail parent) {        super(title);	this.parent = parent;	this.gui = spg;	siFileTitle = new StringItem("", "");	siTime = new StringItem("", "");	siRate = new StringItem("", "");	siKaraoke = new StringItem("", "");	siFeedback = new StringItem("", "");	siStatus = new StringItem("", "");	SimplePlayerGUI.timerInterval = 500;	debugOut("constructor finished");    }        private void appendNewLine(Item item) {    	insertNewLine(size(), item);    }    private void insertNewLine(int pos, Item item) {               	insert(pos, (StringItem)item);                Spacer spacer = new Spacer(3, 10);        spacer.setLayout(Item.LAYOUT_NEWLINE_BEFORE);        if(pos < 8) {            insert(pos++, spacer);        }    }        private void setUpItems() {	// first delete all items	for (int i = size()-1; i>=0; i--) {	    delete(i);	}	karaokeShowing = false;	getGUI();	VideoControl vc = gui.getVideoControl();	Object vitem = null;	if (gui.isFullScreen() && vc!=null) {	    vitem = guiItem;	    if (!(vitem instanceof Item)) {		// we don't need non-Item GUI controls...		vitem = null;	    }	}	if (vitem != null) {	    try{		vc.setDisplayFullScreen(true);		append((Item) vitem);	    } catch (MediaException me) {		Utils.debugOut(me);		// back to non-fullscreen mode		vitem = null;	    }	}	if (vitem == null) {	    makeImageItem();	    appendNewLine(siFileTitle);	    appendNewLine(siTime);	    if (gui.hasRateControl() || gui.hasTempoControl()) {		appendNewLine(siRate);	    }	    if (gui.hasGUIControls()) {		Control[] controls = gui.getControls();		if (controls!=null) {		    for (int i=0; i<controls.length; i++) {			Control ctrl = controls[i];			if (ctrl instanceof GUIControl) {			    guiItem = ((GUIControl) ctrl).initDisplayMode(GUIControl.USE_GUI_PRIMITIVE, null);			    if (guiItem instanceof Item) {				append((Item) guiItem);				if (ctrl instanceof VideoControl) {				    try {					((VideoControl) ctrl).setDisplayFullScreen(false);				    } catch (MediaException me) {					Utils.debugOut(me);				    }				}			    }			}		    }		}	    }	    appendNewLine(siFeedback);	    appendNewLine(siStatus);	}    }        private void makeImageItem() {    	if (gui!=null && !gui.isFullScreen()) {	    if (iiLogo==null) {		Image logo = gui.getLogo();		if (logo!=null) {		    iiLogo = new ImageItem("", logo, 					   ImageItem.LAYOUT_CENTER 					   | ImageItem.LAYOUT_NEWLINE_BEFORE 					   | ImageItem.LAYOUT_NEWLINE_AFTER, "MMA logo");		}	    }	    if (iiLogo != null) {		insert(0, iiLogo);	    }    	}    }        ////////////////////////////// interface Utils.BreadCrumbTrail /////////////////    public Displayable go(Displayable d) {    	return parent.go(d);    }    public Displayable goBack() {    	return parent.goBack();    }        public Displayable replaceCurrent(Displayable d) {    	return parent.replaceCurrent(d);    }        public Displayable getCurrentDisplayable() {    	return parent.getCurrentDisplayable();    }    /////////////////////////// interface SimplePlayerGUI.Parent //////////////////        public Utils.BreadCrumbTrail getParent() {    	return parent;    }        public void setStatus(String s) {    	siStatus.setText(s);    }        public void setFeedback(String s) {    	siFeedback.setText(s);    }        public void setFileTitle(String s) {    	siFileTitle.setText(s);    }    public void updateKaraoke() {	int[] karaokeParams = new int[4];	String[] lines = gui.getKaraokeStr(karaokeParams);	int currLine = karaokeParams[SimplePlayerGUI.KARAOKE_LINE];	int lineCount = karaokeParams[SimplePlayerGUI.KARAOKE_LINE_COUNT];	int syllLen = karaokeParams[SimplePlayerGUI.KARAOKE_SYLLABLE_LENGTH];	int currLinePos = karaokeParams[SimplePlayerGUI.KARAOKE_LINE_INDEX];		int thisLine = 0;		    if (lineCount > maxKaraokeLines) {		    	thisLine = currLine - 1;		    	if (thisLine < 0) {			    thisLine = 0;		    	}		    	if (thisLine + maxKaraokeLines > lineCount) {			    thisLine = lineCount - maxKaraokeLines;		    	} else if (lineCount - thisLine > maxKaraokeLines) {			    lineCount = thisLine + maxKaraokeLines;		    	}		    }	String text = "";		    for (; thisLine < lineCount; thisLine++) {			text+=lines[thisLine]+"\n";		    }    	siKaraoke.setText(text);    	if (!karaokeShowing && !gui.isFullScreen()) {	    // insert karaoke item before feedback line	    for (int i = size()-1; i>=0; i--) {		if (get(i)==siFeedback) {		    if (i>0 && (get(i-1) instanceof ImageItem)) {			i--;		    }		    insertNewLine(i, siKaraoke);		    break;		}	    }	    // do not try to visualize siKaraoke again	    karaokeShowing = true;    	}    }        public void updateTime() {    	if (gui!=null) {	    siTime.setText(gui.getMediaTimeStr());    	}    }    public void updateRate() {	if (getGUI().hasTempoControl()) {	    siRate.setText(gui.getTempoStr());	} else {	    siRate.setText(gui.getRateStr());	}    }        public void updateDisplay() {    }    public void fullScreen(boolean value) {    	setUpItems();    }    //////////////////////////////// interface Utils.ContentHandler ///////////////////////////////        public synchronized void close() {    	if (gui != null) {	    gui.closePlayer();	    gui = null;    	}    }        public boolean canHandle(String url) {    	// TODO ?    	return true;    }        public void handle(String name, String url) {    	Utils.debugOut("SimplePlayerForm: handle "+url);	getGUI().setParent(this);	gui.setSong(name, url);	doHandle();    }    public void handle(String name, InputStream is, String contentType) {	getGUI().setParent(this);	gui.setSong(name, is, contentType);	doHandle();    }    /////////////////////////// implementation /////////////////////////////////////////////////    private synchronized SimplePlayerGUI getGUI() {	if (gui == null) {	    debugOut("create GUI");	    gui = new SimplePlayerGUI();	    gui.initialize(getTitle(), this);	    makeImageItem();	}	return gui;    }    	    private void doHandle() {	debugOut("doHandle");    	setUpItems();        // START HACK	// I want to display the player first, and THEN start prefetching.	// the only way I was able to achieve this was by creating a new thread.	//gui.startPlayer();	//display.callSerially(this);	new Thread(this).start();    }    public void run() {	gui.startPlayer();    }    // END HACK    // for debugging    public String toString() {    	return "SimplePlayerForm";    }}

⌨️ 快捷键说明

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