コード例 #1
0
  public void run() {
    try {
      player = Manager.createPlayer("capture://audio?encoding=audio/basic");
      player.realize();

      rCtl = (RecordControl) player.getControl("RecordControl");

      Control[] c = player.getControls();
      for (int i = c.length - 1; i >= 0; i--) {
        if (c[i] instanceof AudioPathControl) {
          apc = (AudioPathControl) c[i];

          oldPath = apc.getAudioPath();
          apc.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSFREE);
          path = apc.getAudioPath();

          break;
        }
      }

      rCtl.setRecordStream(strm);
      rCtl.startRecord();

      player.start();
    } catch (Exception e) {
      final String msg = e.toString();
      UiApplication.getUiApplication()
          .invokeAndWait(
              new Runnable() {
                public void run() {
                  Dialog.inform(msg);
                }
              });
    }
  }
  /**
   * Plays a tone the specified number of times on the device audio system.
   *
   * @param repeatCount number of times to play tone
   */
  private static void playTone(int repeatCount) throws MediaException, IOException {

    // get tone player
    Player p = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
    p.realize();

    // set tone sequence
    ToneControl tc = (ToneControl) p.getControl("ToneControl");
    tc.setSequence(getToneSequence(repeatCount));

    // crank up the volume
    VolumeControl vc = (VolumeControl) p.getControl("VolumeControl");
    vc.setLevel(BEEP_VOLUME);

    // route audio to speaker phone
    p.prefetch();
    Control[] c = p.getControls();
    for (int i = c.length - 1; i >= 0; --i) {
      if (c[i] instanceof AudioPathControl) {
        AudioPathControl apc = (AudioPathControl) c[i];
        apc.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSFREE);
        break;
      }
    }

    // play
    p.start();
  }