java j2me 保存捕获的音频

 

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 SaveCapturedAudioMIDlet 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 rControl = (RecordControlcapturePlayer.getControl("javax.microedition.media.control.RecordControl");

  public SaveCapturedAudioMIDlet() {
    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();
        display.setCurrent(alert);
        if (rControl == null)
          throw new Exception("No RecordControl available");
        rControl.setRecordLocation("file:///test.wav");
      else {
        throw new Exception("Capture Audio Player is not available");
      }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void startApp() {
    try {
      capturePlayer.start();
      rControl.startRecord();
      Thread.sleep(10000);
      rControl.stopRecord();
      rControl.commit();
      capturePlayer.stop();
      capturePlayer.close();
      playbackPlayer = Manager.createPlayer("file:///test.wav");
      playbackPlayer.start();
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }

  public void commandAction(Command cmd, Displayable disp) {
    if (cmd == exitCommand) {
      destroyApp(true);
      notifyDestroyed();
    }
  }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值