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();
    }
  }
  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);
                }
              });
    }
  }
Example #3
0
  private void showCamera() {
    try {
      mPlayer = Manager.createPlayer("capture://video");
      mPlayer.realize();

      mVideoControl = (VideoControl) mPlayer.getControl("VideoControl");

      Canvas canvas = new CameraCanvas(this, mVideoControl);
      canvas.addCommand(mBackCommand);
      canvas.addCommand(mCaptureCommand);
      canvas.setCommandListener(this);
      mDisplay.setCurrent(canvas);

      /*
      Form form = new Form("Camera form");
      Item item = (Item)mVideoControl.initDisplayMode(
          GUIControl.USE_GUI_PRIMITIVE, null);
      form.append(item);
      form.addCommand(mBackCommand);
      form.addCommand(mCaptureCommand);
      form.setCommandListener(this);
      mDisplay.setCurrent(form);
      */

      mPlayer.start();
    } catch (IOException ioe) {
      handleException(ioe);
    } catch (MediaException me) {
      handleException(me);
    }
  }
 private void releaseResources() {
   if (player != null) {
     try {
       player.stop();
       player.close();
     } catch (Exception e) {
     }
   }
 }
Example #5
0
 private void closePlayer() {
   if (null != player) {
     try {
       player.stop();
     } catch (Exception e) {
     }
     try {
       player.close();
     } catch (Exception e) {
     }
     player = null;
   }
 }
Example #6
0
 private boolean play(String file, int volume) {
   createPlayer(file);
   if (null == file) {
     return false;
   }
   try {
     player.realize();
     setVolume(volume);
     player.prefetch();
     player.start();
   } catch (Exception e) {
     closePlayer();
     return false;
   }
   return true;
 }
Example #7
0
 // sets volume for player
 private void setVolume(int value) {
   try {
     VolumeControl c = (VolumeControl) player.getControl("VolumeControl");
     if ((null != c) && (0 < value)) {
       c.setLevel(value);
     }
   } catch (Exception 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);
                }
              });
    }
  }
Example #9
0
  /* 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();
    }
  }
Example #10
0
  public void capture() {
    try {
      // Get the image.
      byte[] raw = mVideoControl.getSnapshot(null);
      Image image = Image.createImage(raw, 0, raw.length);

      Image thumb = ImageUtility.createThumbnail(image);

      // Place it in the main form.
      if (mMainForm.size() > 0 && mMainForm.get(0) instanceof StringItem) mMainForm.delete(0);
      mMainForm.append(thumb);

      // Flip back to the main form.
      mDisplay.setCurrent(mMainForm);

      // Shut down the player.
      mPlayer.close();
      mPlayer = null;
      mVideoControl = null;
    } catch (MediaException me) {
      handleException(me);
    }
  }