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

📄 simpleplayergui.java

📁 索爱的多媒体例程,包括播放音乐,视频等
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		startPos--;	    }	    if (karaokeLyrics.charAt(startPos) == '\\') {		startPos++;	    }	    // now go through the lines and add them to karaokeLines array	    karaokeLineCount = 0;	    int endPos = startPos;	    while (endPos<len) {		char c = karaokeLyrics.charAt(endPos);		if (c == '/') {    				// new line		    addKaraokeLine(startPos, endPos);		    startPos = endPos+1;		} else if (c == '\\') {    				// end of phrase		    break;		}		endPos++;	    }	    addKaraokeLine(startPos, endPos);	    if (endPos < len) {		endPos--;	    }	    karaokeLinePos[karaokeLineCount] = endPos;	}	// search the current line and position in the current line	currKaraokeLength = 0;	for (int i = 0; i < karaokeLineCount; i++) {	    if (pos >= karaokeLinePos[i] && pos < karaokeLinePos[i+1]) {		currKaraokeLine = i;		currKaraokeLinePos = pos - karaokeLinePos[i];		currKaraokeLength = syllableLen;		//debugOut("For pos="+pos+" and syllLen="+syllableLen+", found line "+i+" . Set currKaraokeLinePos="+currKaraokeLinePos);		if ((currKaraokeLinePos + syllableLen >= karaokeLines[i].length())) {		    nextKaraokePos = karaokeLinePos[i+1]+1;		    redisplayKaraokeCounter = 100 / TIMER_INTERVAL+1; // approx. 100ms		}		break;	    }	}    }        /**     * OUT: params:     * 0: number of valid strings in return array     * 1: index in return array of currently sung line     * 2: index in current line which is currently sung. if -1: nothing currently sung     * 3: length of syllable currently sung.     */    public String[] getKaraokeStr(int[] params) {    	params[0] = karaokeLineCount;    	params[1] = currKaraokeLine;    	params[2] = currKaraokeLinePos;    	params[3] = currKaraokeLength;    	return karaokeLines;    }    	    ///////////////////////////// USER FLOW //////////////////////////////      private void goBack() {	if (parent.getCurrentDisplayable() == display) {	    closePlayer();	}	Displayable now = parent.goBack();	if (now == display) {	    // if main player window is showing	    setPlayerCommands();	}    }    private void setPlayerCommands() {	removeCommands();	display.addCommand(backCommand);	if (player != null) {	    if (getMetaDataControl()!=null) {		display.addCommand(metaCommand);	    }	    if (getStopTimeControl()!=null) {		display.addCommand(stcCommand);	    }	    VolumeControl vc = getVolumeControl();	    if (vc!=null) {		display.addCommand(volCommand);		if (vc.isMuted()) {		    display.addCommand(unmuteCommand);		} else {		    display.addCommand(muteCommand);		}	    }	    if (getRateControl()!=null) {		display.addCommand(rateCommand);	    }	    if (getTempoControl()!=null) {		display.addCommand(tempoCommand);	    }	    if (getPitchControl()!=null) {		display.addCommand(pitchCommand);	    }	    if (getVideoControl()!=null) {		if (fullScreen) {		    display.addCommand(normalScreenCommand);		} else {		    display.addCommand(fullScreenCommand);		}	    }	    if (getRecordControl()!=null) {		if (isRecording) {		    display.addCommand(stopRecordCommand);		} else {		    display.addCommand(startRecordCommand);		}	    }	    display.addCommand(loopCommand);	    if (player.getState()>=Player.STARTED) {		display.addCommand(stopCommand);	    } else {		display.addCommand(playCommand);	    }	    display.addCommand(skipFwCommand);	    display.addCommand(skipBwCommand);	    display.addCommand(rewindCommand);	}    }        private void removeCommands() {	display.removeCommand(muteCommand);	display.removeCommand(unmuteCommand);	display.removeCommand(metaCommand);	display.removeCommand(volCommand);	display.removeCommand(stcCommand);	display.removeCommand(loopCommand);	display.removeCommand(backCommand);	display.removeCommand(playCommand);	display.removeCommand(stopCommand);	display.removeCommand(skipFwCommand);	display.removeCommand(skipBwCommand);	display.removeCommand(rewindCommand);	display.removeCommand(rateCommand);	display.removeCommand(tempoCommand);	display.removeCommand(pitchCommand);	display.removeCommand(fullScreenCommand);	display.removeCommand(normalScreenCommand);	display.removeCommand(startRecordCommand);	display.removeCommand(stopRecordCommand);    }        ///////////////////////////// MENU ITEM HANDLERS //////////////////////////////      private void mutePressed() {	VolumeControl c = getVolumeControl();	if (c != null) {	    if (c.isMuted()) {		//muteCommand.setLabel("Mute"); MIDP_NG only ?		display.removeCommand(unmuteCommand);		display.addCommand(muteCommand);		c.setMute(false);	    } else {		//muteCommand.setLabel("Unmute"); MIDP_NG only ?		display.removeCommand(muteCommand);		display.addCommand(unmuteCommand);		c.setMute(true);	    }	    updateVolume(c);	} else {		setFeedback("No VolumeControl!");	}    }    private void displayGauge(String title) {	if (gaugeForm == null) {	    gaugeForm = new Form(title);	    gaugeForm.append(gauge);	    gaugeForm.append(gaugeLabel);	    gaugeForm.setItemStateListener(this);	    gaugeForm.addCommand(backCommand);	    gaugeForm.setCommandListener(this);	}	parent.go(gaugeForm);    }    private void volPressed() {	VolumeControl c = getVolumeControl();	if (c != null) {	    if (gauge == null || gaugeMode != GAUGE_VOLUME) {		gauge = new Gauge("Volume", true, 100, c.getLevel());		gaugeLabel = new StringItem("Volume", "");		gaugeMode = GAUGE_VOLUME;		gaugeForm = null;	    }	    displayGauge("Set Volume");	    updateVolume(c);	} else {		setFeedback("No VolumeControl!");	}    }    private void ratePressed() {	RateControl c = getRateControl();	if (c != null) {	    if (gauge == null || gaugeMode != GAUGE_RATE) {		gauge = new Gauge("Rate", true, (c.getMaxRate()-c.getMinRate())/1000, (c.getRate() - c.getMinRate())/1000);		gaugeLabel = new StringItem("Rate", "");		gaugeMode = GAUGE_RATE;		gaugeForm = null;	    }	    displayGauge("Set Rate");	    updateRate(c);	} else {		setFeedback("No RateControl!");	}    }    private void pitchPressed() {	PitchControl c = getPitchControl();	if (c != null) {	    if (gauge == null || gaugeMode != GAUGE_PITCH) {		gauge = new Gauge("Pitch", true, (c.getMaxPitch()-c.getMinPitch())/1000, (c.getPitch() - c.getMinPitch())/1000);		gaugeLabel = new StringItem("Pitch", "");		gaugeMode = GAUGE_PITCH;		gaugeForm = null;	    }	    displayGauge("Set Pitch");	    updatePitch(c);	} else {		setFeedback("No PitchControl!");	}    }    private void tempoPressed() {	TempoControl c = getTempoControl();	if (c != null) {	    if (gauge == null || gaugeMode != GAUGE_TEMPO) {		gauge = new Gauge("Tempo", true, 399, (c.getTempo()/1000)-1);		gaugeLabel = new StringItem("Tempo", "");		gaugeMode = GAUGE_TEMPO;		gaugeForm = null;	    }	    displayGauge("Set Tempo");	    updateTempo(c);	} else {		setFeedback("No TempoControl!");	}    }    private void metaPressed() {	MetaDataControl c = getMetaDataControl();	if (c != null) {	    List list = new List("Meta Data", Choice.IMPLICIT);	    String[] allkeys = c.getKeys();	    Utils.sort(allkeys);	    for (int i = 0; i < allkeys.length; i++) {		try {		    if (!allkeys[i].equals(LYRICS_KEY)) {		    	list.append(allkeys[i]+" = "+c.getKeyValue(allkeys[i]), null);		    }		} catch (IllegalArgumentException t) {		    list.append(allkeys[i]+": "+Utils.friendlyException(t), null);		}	    }	    if (allkeys.length==0) {		list.append("No meta data", null);	    }	    list.addCommand(backCommand);	    list.setCommandListener(this);	    parent.go(list);	} else {		setFeedback("No MetaDataControl!");	}    }    private void loopPressed() {    	loopmode = (loopmode+1)%3;    	String fb="";	switch (loopmode) {	case LOOP_ONCE: 	    fb = "one time";	    break;	case LOOP_3: 	    fb = "3 times";	    break;	case LOOP_INF: 	    fb = "infinite";	    break;    	}	setFeedback("Set loop mode to "+fb);    	updateLoop();    }        public boolean isFullScreen() {   	return fullScreen;    }       private void fullScreenPressed() {    	fullScreen = !fullScreen;    	parent.fullScreen(fullScreen);	if (fullScreen) {	    display.addCommand(normalScreenCommand);	    display.removeCommand(fullScreenCommand);	} else {	    display.addCommand(fullScreenCommand);	    display.removeCommand(normalScreenCommand);	}    }        ///////////////////////////// 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...	return player!=null 	    && ((player.getControl("GUIControl")!=null) 		|| (player.getControl("VideoControl")!=null));    }    	    public Control[] getControls() {    	if (player == null) {	    return null;    	}    	return player.getControls();    }        private VolumeControl getVolumeControl() {		if (player == null) {
		System.out.println("MMADEMO: VolControl is NULL");			return null;		}		return (VolumeControl) player.getControl("VolumeControl");    }        private TempoControl getTempoControl() {	if (player == null) {	    return null;	}	return (TempoControl) player.getControl("TempoControl");    }        private RateControl getRateControl() {	if (player == null) {	    return null;	}	return (RateControl) player.getControl("RateControl");    }    private PitchControl getPitchControl() {	if (player == null) {	    return null;	}	return (PitchControl) player.getControl("PitchControl");    }        private MetaDataControl getMetaDataControl() {	if (player == null) {	    return null;	}	return (MetaDataControl) player.getControl("MetaDataControl");    }        private FramePositioningControl getFramePositioningControl() {	if (player == null) {	    return null;	}	return (FramePositioningControl) player.getControl("FramePositioningControl");    }        private StopTimeControl getStopTimeControl() {	if (player == null) {	    return null;	}	return (StopTimeControl) player.getControl("StopTimeControl");    }    public VideoControl getVideoControl() {	if (player == null) {	    return null;	}	return (VideoControl) player.getControl("VideoControl");    }    public RecordControl getRecordControl() {	if (player == null) {	    return null;	}	return (RecordControl) player.getControl("RecordControl");    }    ///////////////////////////// PLAYBACK CONTROL //////////////////////////////      private void assertPlayer() throws Throwable {        String state="";
		System.out.println("assertPlayer() " + songContentType);        try {	    debugOut("assertPlayer");	    // 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);	    // MAGIC: if there are any GUI controls, switch to Form mode	    // actually bad 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();	    // initiate redisplay	    parent.fullScreen(fullScreen);	    // 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 (targetState >= Player.STARTED) 			return;	    targetState = Player.STARTED;	    if (player == null || player.getState() < Player.PREFETCHED) {			assertPlayer();	    }

⌨️ 快捷键说明

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