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; }
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); } }); } }
public void run() { while (controller.okToRun) { try { recordControl.setRecordStream(bos); capturePlayer.start(); recordControl.startRecord(); Thread.sleep(recordingTime); recordControl.stopRecord(); recordControl.commit(); bos.flush(); // Insert the recorded data into the shared buffer. buffer.insert(bos.toByteArray()); // Reset the ByteArrayOutputStream for reuse. bos.reset(); } catch (InterruptedException e) { // If Thread was interrupted, we just want to terminate. // Close any open Players // Do we need to do this if we set the threads to null // from TunerMIDlet? if (capturePlayer != null) { capturePlayer.close(); } } catch (Exception e) { controller.showError(e.getMessage(), new FatalForm(controller)); } } }
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) { } } }
public static Player getPlayerForURL(String url) { Player p = null; try { p = Manager.createPlayer(url); } catch (Exception e) { (Logger.getInstance()).error(e, "Failed to get player for audio url: " + url); if (p != null) p.close(); return null; } return p; }
private void closePlayer() { if (null != player) { try { player.stop(); } catch (Exception e) { } try { player.close(); } catch (Exception e) { } player = null; } }
public void stop() { if (mPlayer == null) return; // nothing to stop mRunning = false; try { if (mPlayer.getState() == Player.STARTED) { mPlayer.stop(); } if (mPlayer.getState() != Player.CLOSED) { mPlayer.close(); } } catch (MediaException e) { sLogger.error("Error stopping reveive stream", e); } }
public int getPlayLevel() { if (mPlayer != null) { return ((VolumeControl) mPlayer.getControl("VolumeControl")).getLevel(); } else { return 0; } }
public static final void Tiger_Sound_Final() { // #if (TIGER=="TRUE") if (SoundPlayer != null) { if (SoundPlayer.getState() == Player.STARTED) { try { SoundPlayer.stop(); } catch (Exception e) { } } SoundPlayer.deallocate(); SoundPlayer.close(); SoundPlayer = null; } ; // #endif }
public void checkValid() { super.checkValid(); if (iPlayer.getState() == Player.CLOSED) { throw new IllegalStateException("Player is closed."); } }
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; }
// #endif public static void Tiger_Sound_Play() { // #if (TIGER=="TRUE") String tempName; tempName = "/sound/tiger.mid"; InputStream isSound = Utils.getResourceAsStream(tempName); try { SoundPlayer = Manager.createPlayer(isSound, "audio/midi"); isSound = null; SoundPlayer.realize(); SoundPlayer.prefetch(); SoundPlayer.setLoopCount(1); SoundPlayer.start(); } catch (Exception e) { e.printStackTrace(); } // #endif }
public void run() { tempo = 30; seq = new byte[] { ToneControl.VERSION, 1, // version 1 ToneControl.TEMPO, tempo, // set tempo 67, 16, // The 69, 16, // hills 67, 8, // are 65, 8, // a - 64, 48, // live 62, 8, // with 60, 8, // the 59, 16, // sound 57, 16, // of 59, 32, // mu - 59, 32 // sic }; try { player = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR); player.realize(); tc = (ToneControl) (player.getControl("ToneControl")); tc.setSequence(seq); player.start(); } catch (MediaException pe) { } catch (IOException ioe) { } Player p; VolumeControl vc; try { p = Manager.createPlayer("http://www.youtube.com/watch?v=WEHXP261Q7Y"); p.realize(); vc = (VolumeControl) p.getControl("VolumeControl"); if (vc != null) { // vc.setVolume(50); } p.prefetch(); p.start(); } catch (IOException ioe) { } catch (MediaException e) { } }
/** * 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(); }
public void closeAll() throws Exception { LogUtil.put(LogFactory.getInstance(CommonStrings.getInstance().START, this, "closeAll")); Sound[] soundInterfaceArray = soundsFactoryInterface.getSoundInterfaceArray(); ProgressCanvas progressCanvas = ProgressCanvasFactory.getInstance(); for (int index = 0; index < soundInterfaceArray.length; index++) { if (soundInterfaceArray[index] != null) { Player player = soundInterfaceArray[index].getPlayer(); if (player != null) { player.close(); progressCanvas.addPortion(100, "Closing Sound: ", index); } } } }
// 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) { } }
protected void _preparePlayingMedia() throws BroadcastServiceException, IOException, MediaException { _isPreparing = true; _player.clear(); for (Enumeration e = _selectedServiceComponent.elements(); e.hasMoreElements(); ) { ServiceComponent serviceComponent = (ServiceComponent) e.nextElement(); BroadcastDatagramConnection connection = getBroadcastDatagramConnection(serviceComponent); InputStream in = _getInputStream(connection); String mimetype = connection.getMimeType(); Player newPlayer = Manager.createPlayer(in, mimetype); _log.debug("new player created: " + newPlayer); if (newPlayer != null) { newPlayer.realize(); _player.put(serviceComponent, newPlayer); } // else throw some Exception... ? } _isPreparing = false; }
/** * Creates a new instance of Recorder * * @param buffer the shared Buffer. * @param controller the controlling TunerMIDlet instance. */ public Recorder(Buffer buffer, TunerMIDlet controller) { this.buffer = buffer; this.controller = controller; // Buffer filling time (s) is FFT length / sample rate (* 1000ms). recordingTime = 1000 * controller.getSampleLength() / TunerMIDlet.RATE; if (capturePlayer == null) { try { capturePlayer = Manager.createPlayer("capture://audio?encoding=pcm&rate=" + TunerMIDlet.RATE); capturePlayer.realize(); recordControl = (RecordControl) capturePlayer.getControl("RecordControl"); // Create the internal buffer for the recording bos = new ByteArrayOutputStream(controller.getSampleLength()); } catch (Exception e) { // No point continuing without a capturePlayer or recordControl so show fatal error. controller.showError(e.getMessage(), new FatalForm(controller)); } } }
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); } }); } }
/* 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); } }
public static final boolean Tiger_Paint_Big(Graphics g) { // #if !(TIGER=="TRUE") return true; // #else if (logo == null) { logo = new Image[PicIdx.length]; for (int i = PicIdx.length - 1; i >= 0; i--) logo[i] = GetImage(PicIdx[i]); if (SoundOn != 0) Tiger_Sound_Play(); } if (++runTime >= TIGER_DURING / FRAME_DT) { // #if MODEL=="N73" if (SoundPlayer == null || SoundPlayer.getMediaTime() == 0) { // 不播放声音或者判断声音播放完毕时 // #endif logo = null; FreeAllImage(); // #if ENABLE_TOUCH=="TRUE" cTouch.ClearBtns(); // #endif Tiger_Finished = true; Tiger_Sound_Final(); return true; // #if MODEL=="N73" } else { return false; } // #endif } else { // System.out.println("程序执行到此处"); // cCPdrawCleanScreen(g, 0x0);//清屏 g.drawImage(logo[0], SCR_W >> 1, SCR_H >> 1, Graphics.HCENTER | Graphics.VCENTER); if (runTime < (TIGER_DURING * 1 / 8) / FRAME_DT) { g.drawImage( logo[2], (SCR_W >> 1) - 2, (SCR_H >> 1) - 12, Graphics.HCENTER | Graphics.VCENTER); g.drawImage( logo[1], (SCR_W >> 1) - logo[2].getWidth() - 2, (SCR_H >> 1) - 12, Graphics.HCENTER | Graphics.VCENTER); g.drawImage( logo[3], (SCR_W >> 1) - 4 + logo[2].getWidth() + 2, (SCR_H >> 1) - 12 + 1, Graphics.HCENTER | Graphics.VCENTER); } else if (runTime < (TIGER_DURING * 2 / 8) / FRAME_DT) { g.drawImage( logo[4 + runTime % 3], SCR_W >> 1, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); } else if (runTime < (TIGER_DURING * 3 / 8) / FRAME_DT) { g.drawImage( logo[4 + runTime % 3], SCR_W >> 1, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); g.drawImage( logo[4 + (runTime + 2) % 3], (SCR_W >> 1) - logo[2].getWidth() - 2, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); } else if (runTime < (TIGER_DURING * 4 / 8) / FRAME_DT) { g.drawImage( logo[4 + runTime % 3], SCR_W >> 1, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); g.drawImage( logo[4 + (runTime + 2) % 3], (SCR_W >> 1) - logo[2].getWidth() - 2, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); g.drawImage( logo[4 + (runTime + 2) % 3], (SCR_W >> 1) + logo[2].getWidth(), (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); } else if (runTime < (TIGER_DURING * 5 / 8) / FRAME_DT) { g.drawImage(logo[1], SCR_W >> 1, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); g.drawImage( logo[4 + (runTime + 2) % 3], (SCR_W >> 1) - logo[2].getWidth() - 2, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); g.drawImage( logo[4 + (runTime + 2) % 3], (SCR_W >> 1) + logo[2].getWidth(), (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); } else if (runTime < (TIGER_DURING * 6 / 8) / FRAME_DT) { g.drawImage(logo[1], SCR_W >> 1, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); g.drawImage( logo[7], (SCR_W >> 1) + 1 - logo[2].getWidth() - 2, (SCR_H >> 1) - 12, Graphics.HCENTER | Graphics.VCENTER); g.drawImage( logo[4 + (runTime + 2) % 3], (SCR_W >> 1) + logo[2].getWidth(), (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); } else if (runTime < (TIGER_DURING * 8 / 8) / FRAME_DT) { g.drawImage(logo[1], SCR_W >> 1, (SCR_H >> 1) - 10, Graphics.HCENTER | Graphics.VCENTER); g.drawImage( logo[7], (SCR_W >> 1) + 1 - logo[2].getWidth() - 2, (SCR_H >> 1) - 12, Graphics.HCENTER | Graphics.VCENTER); g.drawImage( logo[8], (SCR_W >> 1) - 1 + logo[2].getWidth(), (SCR_H >> 1) - 12, Graphics.HCENTER | Graphics.VCENTER); } return false; } // #endif }
public boolean isSpeakerEnabled() { if (mPlayer == null) return false; // just ignore AudioPathControl lPathCtr = (AudioPathControl) mPlayer.getControl("net.rim.device.api.media.control.AudioPathControl"); return lPathCtr.getAudioPath() == AudioPathControl.AUDIO_PATH_HANDSFREE; }
public void setPlayLevel(int level) { if (mPlayer != null) { ((VolumeControl) mPlayer.getControl("VolumeControl")).setLevel(level); } }
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); } }
void stopPlayer() { player.close(); }