private void showCamera() {

    try {

      releaseResources();
      player = Manager.createPlayer("capture://video");
      player.addPlayerListener(this);
      player.realize();

      videoControl = (VideoControl) player.getControl("VideoControl");
      aVideoCanvas = new VideoCanvas();
      aVideoCanvas.initControls(videoControl, player);

      aVideoCanvas.addCommand(CMD_RECORD);
      aVideoCanvas.addCommand(CMD_EXIT);
      aVideoCanvas.setCommandListener(this);
      parentMidlet.getDisplay().setCurrent(aVideoCanvas);

      player.start();
      contentType = player.getContentType();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#2
0
文件: Notify.java 项目: fin-nick/fj
  /* Creates player for file 'source' */
  private void createPlayer(String source) {
    closePlayer();
    try {
      /* What is file extention? */
      String ext = "wav";
      int point = source.lastIndexOf('.');
      if (-1 != point) {
        ext = source.substring(point + 1).toLowerCase();
      }

      InputStream is = getClass().getResourceAsStream(source);
      if (null != is) {
        player = Manager.createPlayer(is, getMimeType(ext));
        player.addPlayerListener(this);
      }
    } catch (Exception e) {
      closePlayer();
    }
  }
  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);
    }
  }