本文整理汇总了Java中javax.microedition.media.MediaException类的典型用法代码示例。如果您正苦于以下问题:Java MediaException类的具体用法?Java MediaException怎么用?Java MediaException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaException类属于javax.microedition.media包,在下文中一共展示了MediaException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPlayer
import javax.microedition.media.MediaException; //导入依赖的package包/类
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());
}
}
示例2: paint
import javax.microedition.media.MediaException; //导入依赖的package包/类
/**
* @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();
}
}
}
示例3: setFocus
import javax.microedition.media.MediaException; //导入依赖的package包/类
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
}
}
}
示例4: takeSnapshot
import javax.microedition.media.MediaException; //导入依赖的package包/类
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;
}
示例5: guessBestEncoding
import javax.microedition.media.MediaException; //导入依赖的package包/类
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;
}
示例6: setFocus
import javax.microedition.media.MediaException; //导入依赖的package包/类
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
}
}
}
示例7: createPlayer
import javax.microedition.media.MediaException; //导入依赖的package包/类
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());
}
}
示例8: play
import javax.microedition.media.MediaException; //导入依赖的package包/类
public void play() {
if(deleted){
return;
}
try {
if(playing == null) {
playing = new Vector();
}
synchronized(MMAPIPlayer.class) {
if(!playing.contains(this)){
playing.addElement(this);
}
}
nativePlayer.start();
} catch (MediaException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.toString());
}
}
示例9: stopAudio
import javax.microedition.media.MediaException; //导入依赖的package包/类
/**
* Stops playback of any audio currently playing, and deallocates
* any associated players or state associated with the current
* audio.
*/
public static void stopAudio() {
synchronized(audioLock) {
currentTag = null;
isPaused = false;
if(audioPlayer != null){
try {
audioPlayer.stop();
} catch (MediaException e) {
e.printStackTrace();
}
audioPlayer.deallocate();
audioPlayer.close();
}
audioPlayer = null;
}
}
示例10: getAcquiredData
import javax.microedition.media.MediaException; //导入依赖的package包/类
protected IAnswerData getAcquiredData() {
try {
processScan();
if (scannedCode != null)
return scannedCode;
else {
System.out.println("Error returning barcode: Scanning failed");
showMessage("Error returning barcode: Scanning failed", true);
return null;
}
} catch (MediaException me) {
showMessage("Error returning image: " + me.getMessage(), false);
return null;
} catch (ImageProcessingException ie) {
showMessage(
"Error returning barcode: " + ie.getMessage() == null ? ""
: ie.getMessage(), barcodeProcessor == null ? false
: true);
return null;
}
}
示例11: stopRecord
import javax.microedition.media.MediaException; //导入依赖的package包/类
public void stopRecord() throws AudioException
{
try
{
recordControl.commit();
recordP.stop();
serviceState = AudioCaptureService.CAPTURE_STOPPED;
}
catch(MediaException me)
{
throw new AudioException(me.getMessage());
}
catch(IOException ioe)
{
System.err.println(ioe.getMessage());
}
}
示例12: CameraCanvas
import javax.microedition.media.MediaException; //导入依赖的package包/类
public CameraCanvas(MIDlet midlet, VideoControl videoControl) {
int width = getWidth();
int height = getHeight();
// mMIDlet = midlet;
videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
try {
videoControl.setDisplayLocation(2, 2);
videoControl.setDisplaySize(width - 4, height - 4);
}
catch (MediaException me) {
try { videoControl.setDisplayFullScreen(true); }
catch (MediaException me2) {}
}
videoControl.setVisible(true);
}
示例13: showCamera
import javax.microedition.media.MediaException; //导入依赖的package包/类
private void showCamera() {
try {
mPlayer = Manager.createPlayer("capture://video");
mPlayer.realize();
mVideoControl = (VideoControl) mPlayer.getControl("VideoControl");
// Command mExitCommand = new Command("Exit", Command.EXIT, 0);
// Command mCameraCommand = new Command("Camera", Command.SCREEN, 0);
mBackCommand = new Command("Back", Command.BACK, 0);
mCaptureCommand = new Command("Capture", Command.SCREEN, 0);
Canvas canvas = new CameraCanvas(null, mVideoControl);
canvas.addCommand(mBackCommand);
canvas.addCommand(mCaptureCommand);
canvas.setCommandListener(this);
J2MEDisplay.setView(canvas);
mPlayer.start();
} catch (IOException ioe) {
handleException(ioe);
} catch (MediaException me) {
handleException(me);
}
}
示例14: CameraCanvas
import javax.microedition.media.MediaException; //导入依赖的package包/类
public CameraCanvas(TioPatinhasMIDlet midlet, VideoControl videoControl) {
int width = getWidth();
int height = getHeight();
mTioPatinhasMIDlet = midlet;
videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
try {
videoControl.setDisplayLocation(2, 2);
videoControl.setDisplaySize(width - 4, height - 4);
}
catch (MediaException me) {
try { videoControl.setDisplayFullScreen(true); }
catch (MediaException me2) {}
}
videoControl.setVisible(true);
}
示例15: stop
import javax.microedition.media.MediaException; //导入依赖的package包/类
/**
* 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");
}
}
}