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();
  }
Пример #3
0
 public void enableSpeaker(boolean value) {
   if (mPlayer == null) return; // just ignore
   AudioPathControl lPathCtr =
       (AudioPathControl) mPlayer.getControl("net.rim.device.api.media.control.AudioPathControl");
   try {
     lPathCtr.setAudioPath(
         value ? AudioPathControl.AUDIO_PATH_HANDSFREE : AudioPathControl.AUDIO_PATH_HANDSET);
     sLogger.info(
         "Speaker is "
             + (lPathCtr.getAudioPath() == AudioPathControl.AUDIO_PATH_HANDSFREE
                 ? "enabled"
                 : "disabled"));
   } catch (Throwable e) {
     sLogger.error("Cannot " + (value ? "enable" : "disable") + " speaker", e);
   }
 }
  public void stop() {
    try {
      apc.setAudioPath(oldPath);

      player.close();
      rCtl.commit();
    } catch (Exception e) {
      final String msg = e.toString();
      UiApplication.getUiApplication()
          .invokeAndWait(
              new Runnable() {
                public void run() {
                  Dialog.inform(msg);
                }
              });
    }
  }
Пример #5
0
  public void start() {
    mRunning = true;
    mSession.setTimestampClock(
        new TimestampClock() {
          public int getCurrentTimestamp() {
            return getCurTs();
          }
        });
    try {
      mPlayer =
          Manager.createPlayer(
              new DataSource(null) {
                SourceStream[] mStream = {mInput};

                public void connect() throws IOException {
                  sLogger.info("connect data source");
                }

                public void disconnect() {
                  sLogger.info("disconnect data source");
                }

                public String getContentType() {
                  return "audio/amr";
                }

                public SourceStream[] getStreams() {
                  return mStream;
                }

                public void start() throws IOException {
                  sLogger.info("start data source");
                }

                public void stop() throws IOException {
                  sLogger.info("start data source");
                }

                public Control getControl(String controlType) {
                  return null;
                }

                public Control[] getControls() {
                  return null;
                }
              });

      mPlayer.addPlayerListener(this);
      mPlayer.realize();
      AudioPathControl lPathCtr =
          (AudioPathControl)
              mPlayer.getControl("net.rim.device.api.media.control.AudioPathControl");
      lPathCtr.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSET);
      mPlayer.prefetch();
      // if ( DeviceInfo.isSimulator() == false) { //only start player on real device
      mPlayer.start();

      if (sLogger.isLevelEnabled(Logger.Info)) sLogger.info("Player is started .");
      // }

    } catch (Throwable e) {
      sLogger.error("player error:", e);
    }
  }