Search in sources :

Example 1 with MediaException

use of javax.microedition.media.MediaException in project CodenameOne by codenameone.

the class AdvancedMultimediaManager method setExposure.

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;
                }
            }
        }
    }
}
Also used : MediaException(javax.microedition.media.MediaException) ExposureControl(javax.microedition.amms.control.camera.ExposureControl)

Example 2 with MediaException

use of javax.microedition.media.MediaException in project CodenameOne by codenameone.

the class MMAPIPlayer method createPlayer.

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());
    }
}
Also used : Player(javax.microedition.media.Player) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException)

Example 3 with MediaException

use of javax.microedition.media.MediaException in project CodenameOne by codenameone.

the class SnapshotThread method takeSnapshot.

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;
}
Also used : MediaException(javax.microedition.media.MediaException) VideoControl(javax.microedition.media.control.VideoControl)

Example 4 with MediaException

use of javax.microedition.media.MediaException in project CodenameOne by codenameone.

the class MMAPIPlayer method createPlayer.

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());
    }
}
Also used : Player(javax.microedition.media.Player) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException)

Example 5 with MediaException

use of javax.microedition.media.MediaException in project CodenameOne by codenameone.

the class MMAPIPlayer method createPlayer.

/**
 * @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());
    }
}
Also used : Player(javax.microedition.media.Player) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException)

Aggregations

MediaException (javax.microedition.media.MediaException)10 IOException (java.io.IOException)4 Player (javax.microedition.media.Player)4 ExposureControl (javax.microedition.amms.control.camera.ExposureControl)2 FocusControl (javax.microedition.amms.control.camera.FocusControl)2 Timer (java.util.Timer)1 VideoControl (javax.microedition.media.control.VideoControl)1