Java Code Examples for javax.microedition.media.MediaException#printStackTrace()

The following examples show how to use javax.microedition.media.MediaException#printStackTrace() . 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: MMAPIPlayer.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
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 2
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @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 3
Source File: MMAPIPlayer.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
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 4
Source File: MMAPIPlayer.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void play() {
    if (deleted) {
        return;
    }
    try {
        nativePlayer.start();
    } catch (MediaException ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex.toString());
    }
}
 
Example 5
Source File: MediaRecorder.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
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 6
Source File: MMAPIPlayer.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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 7
Source File: MMAPIPlayer.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void pause() {
    if(deleted){
        return;
    }
    try {
        if(nativePlayer != null) {
            nativePlayer.stop();
        }
    } catch (MediaException ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex.toString());
    }
}
 
Example 8
Source File: MediaRecorder.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void play() {
    try {
        rc.startRecord();
        recorder.start();
    } catch (MediaException ex) {
        ex.printStackTrace();
    }
}
 
Example 9
Source File: VideoMainScreen.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public VideoMainScreen(MMAPIPlayer p, BlackBerryImplementation impl) {
    super(Manager.NO_VERTICAL_SCROLL);
    this.player = p;
    this.impl = impl;
    this.videoControl = (VideoControl) player.nativePlayer.getControl("VideoControl");

    if (this.videoControl != null) {
        try {
            // Initialize the field where the content of the camera shall be displayed.
            Field videoField = (Field) this.videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
            add(videoField);
            addMenuItem(new MenuItem("Pause", 0, 100) {

                public void run() {
                    player.pause();
                }
            });
            addMenuItem(new MenuItem("Play", 0, 100) {

                public void run() {
                    player.play();
                }
            });
            
            // Display the video control.
            this.videoControl.setDisplayFullScreen(true);
            this.videoControl.setVisible(true);

        } catch (MediaException ex) {
            ex.printStackTrace();
        }
    }
}
 
Example 10
Source File: MediaRecorder.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void play() {
    try {
        rc.startRecord();
        recorder.start();
    } catch (MediaException ex) {
        ex.printStackTrace();
    }
}
 
Example 11
Source File: MMAPIPlayer.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void setTime(int time) {
    if(deleted){
        return;
    }
    try {
        nativePlayer.setMediaTime(time * 1000);
    } catch (MediaException ex) {
        ex.printStackTrace();
    }
}
 
Example 12
Source File: Sound.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
public void play(int loop) {
	try {
		if (loop == 0) {
			loop = -1;
		}
		if (player.getState() == Player.STARTED) {
			player.stop();
		}
		player.setLoopCount(loop);
		player.start();
		postEvent(SOUND_PLAYING);
	} catch (MediaException e) {
		e.printStackTrace();
	}
}
 
Example 13
Source File: MMAPIPlayer.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void prepare() {
    if (deleted) {
        return;
    }
    try {
        nativePlayer.prefetch();
    } catch (MediaException ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex.toString());
    }
}
 
Example 14
Source File: MediaRecorder.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void pause() {
     try {
        rc.stopRecord();
        recorder.stop();
    } catch (MediaException ex) {
        ex.printStackTrace();
    }
}
 
Example 15
Source File: AudioClip.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
public void resume() {
	try {
		player.start();
	} catch (MediaException e) {
		e.printStackTrace();
	}
}
 
Example 16
Source File: AudioClip.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
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 17
Source File: AudioClip.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
public void pause() {
	try {
		player.stop();
	} catch (MediaException e) {
		e.printStackTrace();
	}
}
 
Example 18
Source File: Sound.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
public void stop() {
	try {
		player.stop();
		postEvent(SOUND_STOPPED);
	} catch (MediaException e) {
		e.printStackTrace();
	}
}
 
Example 19
Source File: Sound.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
public void resume() {
	try {
		player.start();
		postEvent(SOUND_PLAYING);
	} catch (MediaException e) {
		e.printStackTrace();
	}
}
 
Example 20
Source File: BlackBerryImplementation.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public void run() {
    try {
        switch (i) {
            case INVOKE_LATER_confirmControlView:
                if (app.getActiveScreen() != canvas) {
                    app.pushScreen(canvas);
                }
                break;

            case INVOKE_LATER_finishEdit:
                finishEdit(val);
                break;

            case INVOKE_LATER_initComponent:
                canvas.add(fld);
                break;

            case INVOKE_LATER_deinitialize:
                canvas.delete(fld);
                break;

            case INVOKE_LATER_showNativeScreen:
                if (app.getActiveScreen() != fld) {
                    app.pushScreen((Screen) fld);
                }
                break;

            case INVOKE_AND_WAIT_calcPreferredSize:
                dim.setWidth(getFieldWidth(fld));
                dim.setHeight(getFieldHeight(fld));
                break;

            case INVOKE_AND_WAIT_setFocus:
                try {
                    // Not sure why an exception is thrown here during a touch event... 
                    if (val) {
                        fld.setFocus();
                    } else {
                        nullFld.setFocus();
                    }
                } catch (Throwable t) {
                    //t.printStackTrace();
                }
                break;
            case INVOKE_LATER_dirty:
                if (fld.getScreen() == canvas) {
                    fld.setDirty(true);
                    canvas.updateRIMLayout();
                }
                break;
            case INVOKE_LATER_startMedia:
                try {
                    v.start();
                } catch (MediaException ex) {
                    ex.printStackTrace();
                }
                break;
        }
        
    } catch (Exception e) {
    }
}