java j2me 捕捉回放音频
来源:互联网 发布:通州的淘宝城在哪里 编辑:程序博客网 时间:2024/05/21 06:45
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;
import javax.microedition.midlet.MIDlet;
public class CapturePlaybackAudioMIDlet extends MIDlet implements CommandListener {
private Display display = null;
private Alert alert = new Alert("Message");
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Player capturePlayer = null;
private Player playbackPlayer = null;
private RecordControl recordControl = null;
private ByteArrayOutputStream bos = new ByteArrayOutputStream();
private ByteArrayInputStream bis = null;
public CapturePlaybackAudioMIDlet() {
display = Display.getDisplay(this);
alert.setTimeout(Alert.FOREVER);
alert.setString("Capturing for 10 seconds.");
alert.addCommand(exitCommand);
alert.setCommandListener(this);
try {
capturePlayer = Manager.createPlayer("capture://audio");
if (capturePlayer != null) {
capturePlayer.realize();
recordControl = (RecordControl) capturePlayer
.getControl("javax.microedition.media.control.RecordControl");
display.setCurrent(alert);
if (recordControl == null)
throw new Exception("No RecordControl available");
bos = new ByteArrayOutputStream(1024);
recordControl.setRecordStream(bos);
} else {
throw new Exception("Capture Audio Player is not available");
}
} catch (Exception e) {
error(e);
}
}
public void startApp() {
try {
capturePlayer.start();
recordControl.startRecord();
Thread.sleep(10000);
recordControl.stopRecord();
recordControl.commit();
capturePlayer.stop();
alert.setString("Well done!");
bos.flush();
bis = new ByteArrayInputStream(bos.toByteArray());
playbackPlayer = Manager.createPlayer(bis, recordControl.getContentType());
playbackPlayer.start();
alert.setString("Playing back ... ");
} catch (Exception e) {
error(e);
} finally {
try {
if (bos != null)
bos.close();
if (bis != null)
bis.close();
} catch (Exception ex) {
error(ex);
}
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command cmd, Displayable disp) {
if (cmd == exitCommand) {
notifyDestroyed();
}
}
private void error(Exception e) {
alert.setString(e.getMessage());
alert.setTitle("Error");
display.setCurrent(alert);
e.printStackTrace();
}
}
- java j2me 捕捉回放音频
- 音频捕捉
- java j2me 保存捕获的音频
- j2me-捕捉游戏操作按键
- J2ME音频播放
- 【转】音频捕捉(directshow)
- Android 媒体 V-音频捕捉
- Linux下的音频采集与回放
- Android音频子系统,音频流的回放(四)
- DirectShow应用——音频捕捉
- TVideoGrabber中如何设置音频捕捉设备
- VC下摄像头视、音频采集及回放技术
- Directshow的音频捕获和回放测试1
- Directshow的音频捕获和回放测试(2)
- Java捕捉系统屏幕
- Java捕捉系统屏幕
- java 异常捕捉
- Java音频
- 自学
- 李开复的几句名言名语
- java j2me 保存捕获的音频
- jsp Servlet 处理表单数据
- 一个新的起点
- java j2me 捕捉回放音频
- 李开复给中国学生的第七封信:你有选择的权利
- 怎么彻底删除服务
- java j2me网络播放器管理
- 脑筋急转弯
- j2me 从网站加载WAV文件
- struts2 的struts.xml配置
- 给中国学生的第八封信:21世纪最需要的7种人才
- 解析256色位图需要注意的一些问题