📄 playmedia7.java
字号:
package com.wy.ch12;
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import javax.microedition.media.*;
public class PlayMedia7 extends MIDlet implements CommandListener{
private Display display;
private Form f;
private Command captureCommand;
private Command playCapturedCommand;
private Command playCommand;
private int currentId=-1;
public PlayMedia7(){
display = Display.getDisplay(this);
f = new Form("录音测试");
captureCommand=new Command("录音", Command.ITEM, 1);
playCapturedCommand=new Command("播放录制的音乐", Command.ITEM, 1);
playCommand=new Command("播放音乐", Command.ITEM, 1);
f.addCommand(captureCommand);
f.addCommand(playCapturedCommand);
f.addCommand(playCommand);
f.setCommandListener(this);
}
public void startApp() {
display.setCurrent(f);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable){
if(command==captureCommand){
new CaptureThread(this).start();
}
if(command==playCapturedCommand){
try {
RecordStore rs=RecordStore.openRecordStore("capture",false);
long modify=rs.getLastModified();
System.out.println("上次记录存储修改时间是:"+modify);
int nextRecordID=rs.getNextRecordID();
System.out.println("下一条添加的记录的ID是:"+nextRecordID);
int recordSize=rs.getRecordSize(nextRecordID-1);
System.out.println("最后一条记录的大小是:"+recordSize+"字节");
int recordNum=rs.getNumRecords();
System.out.println("记录存储中的记录数量是:"+recordNum);
int size=rs.getSize();
System.out.println("记录存储占用的空间是:"+size+"字节");
int availSize=rs.getSizeAvailable();
System.out.println("记录存储可扩展的空间是:"+availSize+"字节");
InputStream in = null;
System.out.println("currentId:"+currentId);
if (currentId!=-1) {
in = new ByteArrayInputStream(rs.getRecord(currentId));
}else{
return;
}
Player p;
try {
p = Manager.createPlayer(in, "audio/x-wav");
p.start();
} catch (MediaException ex) {
System.out.println("失败");
return;
} catch (IOException ex) {
System.out.println("失败");
return;
}
} catch (RecordStoreException ex) {
System.out.println("失败");
return;
}
}
if(command==playCommand){
try {
InputStream is = getClass().getResourceAsStream("/test-wav.wav");
Player p = Manager.createPlayer(is, "audio/X-wav");
p.start();
} catch (Exception e){
System.out.println("失败");
return;
}
}
}
public int getCurrentId() {
return currentId;
}
public void setCurrentId(int currentId) {
this.currentId = currentId;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -