javax.microedition.media.MediaException Java Examples
The following examples show how to use
javax.microedition.media.MediaException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdvancedMultimediaManager.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void setFocus(Controllable player) { FocusControl focusControl = (FocusControl) getControl(player, "javax.microedition.amms.control.camera.FocusControl"); if (focusControl != null) { try { if (focusControl.isMacroSupported() && !focusControl.getMacro()) { focusControl.setMacro(true); } if (focusControl.isAutoFocusSupported()) { focusControl.setFocus(FocusControl.AUTO); try { Thread.sleep(FOCUS_TIME_MS); // let it focus... } catch (InterruptedException ie) { // continue } focusControl.setFocus(FocusControl.AUTO_LOCK); } } catch (MediaException me) { // continue } } }
Example #2
Source File: SnapshotThread.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private byte[] takeSnapshot() throws MediaException { String bestEncoding = guessBestEncoding(); VideoControl videoControl = barCodeScanner.getVideoControl(); if (videoControl == null) { throw new MediaException("Can't obtain video control"); } byte[] snapshot = null; try { snapshot = videoControl.getSnapshot("".equals(bestEncoding) ? null : bestEncoding); } catch (MediaException me) { } if (snapshot == null) { // Fall back on JPEG; seems that some cameras default to PNG even // when PNG isn't supported! snapshot = videoControl.getSnapshot("encoding=jpeg"); if (snapshot == null) { throw new MediaException("Can't obtain a snapshot"); } } return snapshot; }
Example #3
Source File: Player.java From J2ME-Loader with Apache License 2.0 | 6 votes |
public static void play(Clip clip, int repeat) { if (repeat < -1) { throw new IllegalArgumentException("Repeat must be -1 or greater"); } if (clip.getPriority() < priority) { return; } if (player != null) { player.close(); } if (repeat != -1) { repeat++; } player = clip.getPlayer(); player.setLoopCount(repeat); Display.getDisplay(null).vibrate(clip.getVibration()); try { player.start(); } catch (MediaException e) { e.printStackTrace(); } }
Example #4
Source File: BasicMediaProcessor.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
/** * Stops processing temporarily. If the * <code>MediaProcessor</code> is in a <i>UNREALIZED</i>, <i>REALIZED</i> or <i>STOPPED</i> state, the * call is ignored. Otherwise, the <code>MediaProcessor</code> * either throws a <code>MediaException</code> or moves to * <i>STOPPED</i> state and posts <code>PROCESSING_STOPPED</code> event to <code>MediaProcessorListener</code>s. * * @throws MediaException if the <code>MediaProcessor</code> * could not be stopped. */ public final void stop() throws MediaException { /* do nothing if not in STARTED state */ if (state != STARTED) { return; } synchronized (stateLock) { if (state != STARTED) { return; } if (doStop()) { notifyStopped(); } else { throw new MediaException("Failed to stop operation"); } } }
Example #5
Source File: SnapshotThread.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private synchronized String guessBestEncoding() throws MediaException { if (bestEncoding == null) { // Check this property, present on some Nokias? String supportsVideoCapture = System.getProperty("supports.video.capture"); if ("false".equals(supportsVideoCapture)) { throw new MediaException("supports.video.capture is false"); } bestEncoding = ""; String videoSnapshotEncodings = System.getProperty("video.snapshot.encodings"); if (videoSnapshotEncodings != null) { // We know explicitly what the camera supports; see if PNG is among them since // Image.createImage() should always support it int pngEncodingStart = videoSnapshotEncodings.indexOf("encoding=png"); if (pngEncodingStart >= 0) { int space = videoSnapshotEncodings.indexOf(' ', pngEncodingStart); bestEncoding = space >= 0 ? videoSnapshotEncodings.substring(pngEncodingStart, space) : videoSnapshotEncodings.substring(pngEncodingStart); } } } return bestEncoding; }
Example #6
Source File: GameCanvasImplementation.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * @inheritDoc */ public void paint(com.codename1.ui.Graphics g) { if (isVisible()) { try { VideoControl vidc = (VideoControl) getVideoControl(this); if (isFullScreen()) { vidc.setDisplayLocation(0, 0); vidc.setDisplaySize(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight()); } else { vidc.setDisplayLocation(getAbsoluteX(), getAbsoluteY()); int w = getWidth(); int h = getHeight(); if (vidc.getDisplayWidth() != w || vidc.getDisplayHeight() != h) { vidc.setDisplaySize(w, h); } } } catch (MediaException ex) { ex.printStackTrace(); } } }
Example #7
Source File: BasicDirectModule.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
public void addPlayer( Player player ) throws MediaException { checkIfPlayerIsNull( player ); checkPlayerStates( player ); if( _players.containsKey( player ) ) { throw new IllegalArgumentException( "Cannot add a Player to a Module if either the Player or one " + "of its MIDI channels is already part of the Module" ); } doAddPlayer( player ); _players.put( player, new PlayerConnectionInfo() ); }
Example #8
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public static MMAPIPlayer createPlayer(InputStream stream, String mimeType, Runnable onCompletion) throws IOException { try { Player p = Manager.createPlayer(stream, mimeType); p.realize(); MMAPIPlayer m = new MMAPIPlayer(p); m.bindPlayerCleanupOnComplete(p, stream, onCompletion); return m; } catch (MediaException ex) { if("audio/mpeg".equals(mimeType)) { return createPlayer(stream, "audio/mp3", onCompletion); } ex.printStackTrace(); throw new IOException(ex.toString()); } }
Example #9
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void play() { if (deleted) { return; } try { nativePlayer.start(); } catch (MediaException ex) { ex.printStackTrace(); throw new RuntimeException(ex.toString()); } }
Example #10
Source File: MediaRecorder.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public MediaRecorder(String path) throws IOException { try { String [] supportedContentType = Manager.getSupportedContentTypes("capture"); boolean amrSupported = false; for (int i = 0; i < supportedContentType.length; i++) { if(supportedContentType[i].equals("audio/amr")){ amrSupported = true; } } if(amrSupported){ try { //some j2me devices will report they supports amr, but they are actually //don't so we will try to realize the player and if fails the //fallback would be to create it with the default capture encoding recorder = Manager.createPlayer("capture://audio?encoding=audio/amr"); recorder.realize(); } catch (Exception e) { recorder = Manager.createPlayer("capture://audio"); recorder.realize(); } }else{ recorder = Manager.createPlayer("capture://audio"); recorder.realize(); } rc = (RecordControl) recorder.getControl("RecordControl"); out = FileSystemStorage.getInstance().openOutputStream(path); rc.setRecordStream(out); } catch (MediaException ex) { ex.printStackTrace(); } }
Example #11
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void setTime(int time) { if (deleted) { return; } try { nativePlayer.setMediaTime(time * 1000); } catch (MediaException ex) { ex.printStackTrace(); } }
Example #12
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void pause() { if (deleted) { return; } try { if (nativePlayer != null) { nativePlayer.stop(); } } catch (MediaException ex) { ex.printStackTrace(); throw new RuntimeException(ex.toString()); } }
Example #13
Source File: AudioClip.java From J2ME-Loader with Apache License 2.0 | 5 votes |
public void resume() { try { player.start(); } catch (MediaException e) { e.printStackTrace(); } }
Example #14
Source File: BaseModule.java From J2ME-Loader with Apache License 2.0 | 5 votes |
@Override public void addPlayer(Player player) throws MediaException { if (player == null) { throw new IllegalArgumentException("Player is null."); } if (player.getState() == Player.CLOSED) { throw new IllegalStateException("Can't add Player while it's in CLOSED state."); } players.add(player); }
Example #15
Source File: MIDPVideoRenderer.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
public void setDisplaySize(int width, int height) throws javax.microedition.media.MediaException { checkState(); if (width < 1 || height < 1) throw new IllegalArgumentException("Invalid size"); boolean sizeChanged = (dw != width || dh != height); if (fsmode) { // Just store sizes in fullscreen mode synchronized (dispBoundsLock) { tmpdw = width; tmpdh = height; } } else { synchronized (dispBoundsLock) { dw = width; dh = height; } scaleToDest(); if (pvis) if (mmItem != null) mmItem.refresh(true); else if (cvis) canvas.repaint(); } // Makes sense only if NOT in Full Screen mode if (sizeChanged && !fsmode) player.sendEvent(PlayerListener.SIZE_CHANGED, this); }
Example #16
Source File: MMCustomItem.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
protected void keyPressed(int keyCode) { if (callerVideoControl != null) try { callerVideoControl.setDisplayFullScreen(false); } catch (MediaException me) {} super.keyPressed(keyCode); }
Example #17
Source File: AudioClip.java From J2ME-Loader with Apache License 2.0 | 5 votes |
public void play(int loop, int volume) { try { if (loop == 0) { loop = -1; } if (player.getState() == Player.STARTED) { player.stop(); } player.setLoopCount(loop); player.start(); } catch (MediaException e) { e.printStackTrace(); } }
Example #18
Source File: Sound.java From J2ME-Loader with Apache License 2.0 | 5 votes |
public void resume() { try { player.start(); postEvent(SOUND_PLAYING); } catch (MediaException e) { e.printStackTrace(); } }
Example #19
Source File: MMCustomItem.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
protected void hideNotify() { if (callerVideoControl != null) try { callerVideoControl.setDisplayFullScreen(false); } catch (MediaException me) {} super.hideNotify(); }
Example #20
Source File: AdvancedMultimediaManager.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void setExposure(Controllable player) { ExposureControl exposureControl = (ExposureControl) getControl(player, "javax.microedition.amms.control.camera.ExposureControl"); if (exposureControl != null) { int[] supportedISOs = exposureControl.getSupportedISOs(); if (supportedISOs != null && supportedISOs.length > 0) { int maxISO = Integer.MIN_VALUE; for (int i = 0; i < supportedISOs.length; i++) { if (supportedISOs[i] > maxISO) { maxISO = supportedISOs[i]; } } try { exposureControl.setISO(maxISO); } catch (MediaException me) { // continue } } String[] supportedMeterings = exposureControl.getSupportedLightMeterings(); if (supportedMeterings != null) { for (int i = 0; i < supportedMeterings.length; i++) { if (DESIRED_METERING.equals(supportedMeterings[i])) { exposureControl.setLightMetering(DESIRED_METERING); break; } } } } }
Example #21
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * @inheritDoc */ public static MMAPIPlayer createPlayer(String uri, Runnable onCompletion) throws IOException { try { Player p = Manager.createPlayer((String)uri); p.realize(); MMAPIPlayer m = new MMAPIPlayer(p); m.bindPlayerCleanupOnComplete(p, null, onCompletion); return m; } catch (MediaException ex) { ex.printStackTrace(); throw new IOException(ex.toString()); } }
Example #22
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void prepare() { if(deleted){ return; } try { nativePlayer.prefetch(); } catch (MediaException ex) { ex.printStackTrace(); throw new RuntimeException(ex.toString()); } }
Example #23
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void pause() { if(deleted){ return; } try { if(nativePlayer != null) { nativePlayer.stop(); } } catch (MediaException ex) { ex.printStackTrace(); throw new RuntimeException(ex.toString()); } }
Example #24
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void setTime(int time) { if(deleted){ return; } try { nativePlayer.setMediaTime(time * 1000); } catch (MediaException ex) { ex.printStackTrace(); } }
Example #25
Source File: MediaRecorder.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public MediaRecorder(String path, String mimeType) throws IOException { try { //recorder = Manager.createPlayer("capture://audio?encoding=audio/amr&bitrate=12200&voipMode=true"); recorder = Manager.createPlayer("capture://audio?encoding="+mimeType); recorder.realize(); rc = (RecordControl) recorder.getControl("RecordControl"); out = FileSystemStorage.getInstance().openOutputStream(path); rc.setRecordStream(out); } catch (MediaException ex) { ex.printStackTrace(); } }
Example #26
Source File: MediaRecorder.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void play() { try { rc.startRecord(); recorder.start(); } catch (MediaException ex) { ex.printStackTrace(); } }
Example #27
Source File: AudioCanvas.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
protected void pointerPressed(int x, int y) { if (!touch && !nHD_portrait) { return; } pressed = true; pressed_x = x; pressed_y = y; selected = findSelectedArea(pressed_y); repaint(); serviceRepaints(); if (selected > 0 && selected <= countOfPlayers) { try { pool.playSound(selected - 1); } catch (MediaException e) { // Swallow the exception. } } else { if (midletVolume < 100) { midletVolume += 10; } else if (midletVolume >= 100) { midletVolume = 0; } pool.setVolumeLevel(midletVolume); midlet.midletVolume = midletVolume; repaint(); } }
Example #28
Source File: BasicMediaProcessor.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
/** * Sets the input of the media processor. * @param input The <code>InputStream</code> to be used as input. * @param length The estimated length of the processed media in bytes. Since the input * is given as an <code>InputStream</code>, the implementation cannot find out * what is the length of the media until it has been processed. The estimated * length is used only when the <code>progress</code> method is used to query the * progress of the processing. If the length is not known, UNKNOWN should be passed * as a length. * @throws IllegalStateException if the <code>MediaProcessor</code> * was not in UNREALIZED or REALIZED state. * @throws javax.microedition.media.MediaException if input can not be given as a stream. * @throws IllegalArgumentException if input is null. * @throws IllegalArgumentException if length < 1 and length != UNKNOWN. * */ public void setInput(InputStream input, int length) throws javax.microedition.media.MediaException { inputWasSet = false; synchronized (stateLock) { if (state != UNREALIZED && state != REALIZED) { throw new IllegalStateException("Invalid state " + state); } if (null == input) { throw new IllegalArgumentException("Invalid input stream"); } if (length < 1 && length != UNKNOWN) { throw new IllegalArgumentException("Invalid input stream length " + length); } inputWasSet = doSetInput(input, length); // Reset object. Use stream. inputObject = null; inputStream = input; inputStreamLength = length; if(isRealizable()) notifyRealized(); } }
Example #29
Source File: MMCustomItem.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
protected void pointerPressed(int x, int y) { if (callerVideoControl != null) try { callerVideoControl.setDisplayFullScreen(false); } catch (MediaException me) {} super.pointerPressed(x, y); }
Example #30
Source File: BasicDirectModule.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
public void addMIDIChannel( Player player, int channel ) throws MediaException { checkChannelNumberRange( channel ); checkIfPlayerIsNull( player ); checkIfPlayerIsMIDI( player ); checkPlayerStates( player ); PlayerConnectionInfo conn = ( PlayerConnectionInfo )_players.get( player ); if( conn != null ) { if( !conn.canAddMIDIChannel( channel ) ) { throw new IllegalArgumentException( "Cannot add a MIDI channel to a Module if either the channel or the whole " + "Player is already part of the Module" ); } } doAddMIDIChannel( player, channel ); if( conn != null ) { conn.addMIDIChannel( channel ); } else { conn = new PlayerConnectionInfo( channel ); _players.put( player, conn ); } }