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 synchronized void release() { if (player != null) { player.removePlayerListener(this); player.close(); } player = null; }
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) { } } }
private void closePlayer() { if (null != player) { try { player.stop(); } catch (Exception e) { } try { player.close(); } catch (Exception e) { } player = null; } }
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; }
// 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) { } }
/* 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 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); } }