📄 simpleplayergui.java
字号:
} catch (IllegalStateException ise) { // thrown when player is closed } return "--:--:-"; } public String getTempoStr() { if (player!=null) { TempoControl tc = getTempoControl(); if (tc != null) { int tempo = tc.getTempo(); return toFloatString((tempo+50)/100,1) +"bpm (eff: " +toFloatString((int) (((((long) tc.getRate())*((long) tempo)/100000)+50)/100l), 1)+")"; } } return ""; } public String getRateStr() { if (player!=null) { RateControl rc = getRateControl(); if (rc!=null) { return "Rate: "+toFloatString(rc.getRate()/100,1)+"%"; } } return ""; } /** * switch to next karaoke screen */ private void displayNextKaraokePhrase() { if (karaokeLyrics != null && karaokeLineCount > 0 && karaokeLines != null && nextKaraokePos >= 0) { if (nextKaraokePos < karaokeLyrics.length() && nextKaraokePos > karaokeLinePos[currKaraokeLine] ) { setupKaraokeLines(nextKaraokePos, 0); updateKaraoke(); } } } private void addKaraokeLine(int start, int end) { if (karaokeLines == null || karaokeLines.length <= karaokeLineCount) { String[] newKL = new String[karaokeLineCount+4]; if (karaokeLines != null) { System.arraycopy(karaokeLines, 0, newKL, 0, karaokeLineCount); } karaokeLines = newKL; int[] newKLP = new int[karaokeLineCount+5]; // one more than karaokeLines.length if (karaokeLinePos != null) { System.arraycopy(karaokeLinePos, 0, newKLP, 0, karaokeLineCount+1); } karaokeLinePos = newKLP; } karaokeLines[karaokeLineCount] = karaokeLyrics.substring(start, end); karaokeLinePos[karaokeLineCount++] = start; } private void setupKaraokeLines(int pos, int syllableLen) { int len = (karaokeLyrics == null)?0:karaokeLyrics.length(); if (len == 0) { debugOut("no karaoke lyrics"); return; } // cancel automatic display of next line if it is already displayed nextKaraokePos = -1; if (pos < 0 || pos >= len) { karaokeLineCount = 0; debugOut("setupKaraokeLines: pos out of bounds!"); return; } // the strings in karaokeLines never start with a control character while (karaokeLyrics.charAt(pos) == '\\' || karaokeLyrics.charAt(pos) == '/') { pos++; syllableLen--; } if (syllableLen<0) { syllableLen=0; } if (karaokeLinePos == null || karaokeLineCount == 0 || pos < karaokeLinePos[0] || pos >= karaokeLinePos[karaokeLineCount]) { // need to re-setup karaoke lines // first find the start of this phrase int startPos = pos; while (karaokeLyrics.charAt(startPos) != '\\' && startPos > 0) { 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 / DEFAULT_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) { //Removed temporary by tg157416 //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) { display.addCommand(normalScreenCommand); 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); if (parent instanceof SimplePlayerCanvas) { // Canvas player uses the keys for control, // enable a simple help display.addCommand(helpCommand); } } } 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); display.removeCommand(helpCommand); } // /////////////////////////// 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) { int minRate = c.getMinRate() / 1000; int maxRate = c.getMaxRate() / 1000; // limit to LIMIT_RATE to improve usability if (maxRate > LIMIT_RATE) { maxRate = LIMIT_RATE; } int currRate = c.getRate()/1000; gauge = new Gauge("Rate", true, maxRate - minRate, currRate - minRate); 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() { // this may not be accurate - the user can modify that with the keys return fullScreen; } public boolean toggleFullScreen() { VideoControl vc = getVideoControl(); Utils.debugOut("toggleFullScreen"); if (vc != null) { try { vc.setDisplayFullScreen(!fullScreen); fullScreen = !fullScreen; parent.fullScreen(fullScreen); Utils.debugOut("Successfully set to "+(fullScreen?"full screen":"normal screen")); } catch (Exception e) { fullScreen = false; display.removeCommand(fullScreenCommand); display.removeCommand(normalScreenCommand); error(e); } } else { setFeedback("No VideoControl!"); } return fullScreen; } private void fullScreenPressed() { fullScreen = false; toggleFullScreen(); } private void normalScreenPressed() { fullScreen = true; toggleFullScreen(); } public void stepFrame(int frames) { FramePositioningControl fpc = getFramePositioningControl(); if (fpc != null) { fpc.skip(frames);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -