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

📄 simpleplayergui.java

📁 一个非常典型的J2ME多媒体应用例子
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	fullScreen = false;	toggleFullScreen();    }    private void normalScreenPressed() {	fullScreen = true;	toggleFullScreen();    }    public void stepFrame(int frames) {	FramePositioningControl fpc = getFramePositioningControl();	if (fpc != null) {	    fpc.skip(frames);	} else {	    setFeedback("No FramePositioningControl!");	}    }    // /////////////////////////// CONTROLS ///////////////////////////////////    public boolean hasRateControl() {	return getRateControl()!=null;    }    public boolean hasTempoControl() {	return getTempoControl()!=null;    }    public boolean hasGUIControls() {	// a player which provides VideoControl should also	// always return GUIControl. Just to be sure...	try {	    if (player != null) {		return ((player.getControl("GUIControl")!=null)			|| (player.getControl("VideoControl")!=null));	    }	} catch (IllegalStateException ise) {	    // thrown when player is closed	}	return false;    }    public Control[] getControls() {	try {	    if (player != null) {		return player.getControls();	    }	} catch (IllegalStateException ise) {	    // thrown when player is closed	}	return null;    }    private VolumeControl getVolumeControl() {	try {	    if (player != null) {		return (VolumeControl) player.getControl("VolumeControl");	    }	} catch (IllegalStateException ise) {	    // thrown when player is closed	}	return null;    }    private TempoControl getTempoControl() {	try {	    if (player != null) {		return (TempoControl) player.getControl("TempoControl");	    }	} catch (IllegalStateException ise) {	    // thrown when player is closed	}	return null;    }    private RateControl getRateControl() {	try {	    if (player != null) {		return (RateControl) player.getControl("RateControl");	    }	} catch (IllegalStateException ise) {	    // thrown when player is closed	}	return null;    }    private PitchControl getPitchControl() {	try {	    if (player != null) {		return (PitchControl) player.getControl("PitchControl");	    }	} catch (IllegalStateException ise) {	    // thrown when player is closed	}	return null;    }    private MetaDataControl getMetaDataControl() {	try {	    if (player != null) {		return (MetaDataControl) player.getControl("MetaDataControl");	    }	} catch (IllegalStateException ise) {	    // thrown when player is closed	}	return null;    }    private FramePositioningControl getFramePositioningControl() {	try {	    if (player != null) {		return (FramePositioningControl) player.getControl("FramePositioningControl");	    }	} catch (IllegalStateException ise) {	    // thrown when player is closed	}	return null;    }    private StopTimeControl getStopTimeControl() {	try {	    if (player != null) {		return (StopTimeControl) player.getControl("StopTimeControl");	    }	} catch (IllegalStateException ise) {	    // thrown when player is closed	}	return null;    }    public VideoControl getVideoControl() {	try {	    if (player != null) {		return (VideoControl) player.getControl("VideoControl");	    }	} catch (IllegalStateException ise) {	    // thrown when player is closed	}	return null;    }    public RecordControl getRecordControl() {	try {	    if (player != null) {		return (RecordControl) player.getControl("RecordControl");	    }	} catch (IllegalStateException ise) {	    // thrown when player is closed	}	return null;    }    // /////////////////////////// PLAYBACK CONTROL ///////////////////////////    private void assertPlayer() throws Throwable {	String state="";	try {	    debugOut("assertPlayer");	    fullScreen = false;	    // make sure we can go back, even if failed	    display.removeCommand(backCommand);	    display.addCommand(backCommand);	    if (player == null) {		if (songInputStream == null) {		    state="Opening "+songLocator; setStatus(state+"...");		    player = Manager.createPlayer(songLocator);		} else {		    state="Opening "+songName; setStatus(state+"...");		    player = Manager.createPlayer(songInputStream, songContentType);		}	    }	    player.addPlayerListener(this);	    //System.out.println("player = " + player);	    state="Realizing"; setStatus(state+"...");	    player.realize();	    state="Prefetching"; setStatus(state+"...");	    player.prefetch();	    state="Prefetched"; setStatus(state);	    if (USE_FORM_PLAYER_FOR_VIDEO) {		// MAGIC: if there are any GUI controls, switch to Form mode		// this is not nice design...		if (hasGUIControls() && !(parent instanceof SimplePlayerForm)) {		    System.gc();		    state="Setting up GUI"; setStatus(state+"...");		    Parent newParent = new SimplePlayerForm(parent.getTitle(), this, parent.getParent());		    debugOut("created");		    setParent(newParent);		    parent.replaceCurrent(display);		    state="GUI is set up."; setStatus(state);		    debugOut("Changed to form-based player.");		}	    }	    setPlayerCommands();	    // notify the display class	    parent.setupDisplay();	    // use TITLE meta data if existant for display	    MetaDataControl mc = getMetaDataControl();	    if (mc != null) {		int titleCount=0;		String title = "";		try {		    title = mc.getKeyValue(MetaDataControl.TITLE_KEY);		    if (title != null && title != "") {			titleCount++;			while (true) {			    String n = mc.getKeyValue(MetaDataControl.TITLE_KEY+(titleCount+1));			    if (n == null || n == "") {				break;			    }			    titleCount++;			}		    }		} catch (IllegalArgumentException me) {		    // title key doesn't exist		}		// now number of titles is known		if (titleCount > 0) {		    songDisplayNames = new String[titleCount];		    songDisplayNames[0] = title;		    try {			for (int i=1; i<titleCount; i++) {			    songDisplayNames[i] = mc.getKeyValue(MetaDataControl.TITLE_KEY+(i+1));			}		    } catch (IllegalArgumentException me) {}		    currSongDisplay = 0;		}		try {		    String l = mc.getKeyValue(LYRICS_KEY);		    if (l != null && l != "") {			karaokeMode = true;			karaokeLyrics = l;		    }		} catch (IllegalArgumentException me) {		    // lyrics key doesn't exist		}	    }	    durationUpdated();	} catch (Throwable t) {	    player=null;	    setStatus("");	    throw new MediaException(Utils.friendlyException(t)+" at "+state);	}    }    public void startPlayer() {	try {	    debugOut("startPlayer");	    if (player == null || player.getState() < Player.PREFETCHED) {		assertPlayer();	    }	    if (player == null || player.getState() >= Player.STARTED) {		return;	    }	    updateLoop();	    // auto-rewind	    try {		long duration = player.getDuration();		if (duration != Player.TIME_UNKNOWN && player.getMediaTime() >= duration) {		    player.setMediaTime(0);		}	    } catch (MediaException e) {		// nothing to do	    }	    if (player.getMediaTime() == 0) {		setupKaraokeLines(0, 0);		updateKaraoke();	    } else {		clearKaraoke();	    }	    setStatus("Starting...");	    player.start();	    setStatus("Playing");	    setFeedback("");	    // tempo may have changed due to new position	    updateTempo(null);	} catch (Throwable t) {	    error(t);	}    }    public void closePlayer() {	if (player != null) {	    setStatus("Stopping...");	    try {		player.stop();	    } catch (Exception e) {}	    setStatus("Closing...");	    player.close();	    setStatus("Closed");	    player = null;	    initialize();	}    }    public void pausePlayer() {	if (player != null) {	    setStatus("Stopping...");	    try {		player.stop();	    } catch (Exception e) {}	    setStatus("Stopped");	    setFeedback("");	}    }    public void togglePlayer() {	if (player!=null) {	    if (player.getState() == Player.STARTED) {		pausePlayer();	    } else {		startPlayer();	    }	}    }    /** fast forward or fast backward */    public void skip(boolean backwards) {	if (player != null) {	    try {		long mTime = player.getMediaTime();		// default 10 sec		long jump = 10000000;		long duration = player.getDuration();		if (duration >= 0) {		    // skip 5%		    jump = duration / 20;		    if (jump < 2000000)			jump = 2000000; // Skip at least 2 seconds		}		if (backwards) {		    // Jump backward		    setMediaTime(mTime-jump);		} else {		    // Jump forward		    setMediaTime(mTime+jump);		}	    } catch (IllegalStateException ise) {		// thrown when player is closed		error(ise);	    }	}    }    public void stopAfterTime() {	int delay = 5000000; // 5 seconds	StopTimeControl stc = getStopTimeControl();	if (stc != null) {	    try {		stc.setStopTime(StopTimeControl.RESET);		stc.setStopTime(player.getMediaTime()+delay);		setFeedback("Stop in "+(delay/1000000)+" seconds.");	    } catch (IllegalStateException ise) {		error(ise);	    }	} else {	    setFeedback("No StopTimeControl!");	}    }    public void changeRate(boolean slowdown) {	int diff = 10000; // 10%	if (slowdown) {	    diff = -diff;	}	RateControl rc = getRateControl();	if (rc != null) {	    int ocr = rc.getRate();	    int ncr = ocr + diff;	    int maxRate = rc.getMaxRate();	    if (maxRate > LIMIT_RATE*1000) {		maxRate = LIMIT_RATE * 1000;	    }	    if (ncr >= rc.getMinRate() && ncr <= maxRate) {		int ecr = rc.setRate(ncr);		setFeedback("New rate: "+toFloatString(ecr, 3)+"%");		updateRate(rc);		// rate changes effective tempo.		updateTempo(null);	    }	} else {	    setFeedback("No RateControl!");	}    }    public void setMediaTime(long time) {	if (player == null) {	    return;	}	try {	    setFeedback("Set MediaTime to "+timeDisplay(time));	    player.setMediaTime(time);	    updateTime();	    clearKaraoke();	    updateTempo(null);	} catch (Exception e) {	    error(e);	}    }    public void changeVolume(boolean decrease) {	int diff = 10;	if (decrease) {	    diff = -diff;	}	VolumeControl vc = getVolumeControl();	if (vc != null) {	    int cv = vc.getLevel();	    cv += diff;	    vc.setLevel(cv);	    updateVolume(vc);	} else {	    setFeedback("No VolumeControl!");	}    }    public void toggleMute() {	VolumeControl vc = getVolumeControl();	if (vc != null) {	    vc.setMute(!vc.isMuted());	    updateVolume(vc);	} else {	    setFeedback("No VolumeControl!");	}    }    public void transpose(boolean down) {	int diff = 1000; // 1 semitone	if (down) {	    diff = -diff;	}	PitchControl pc = getPitchControl();	if (pc != null) {

⌨️ 快捷键说明

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