Java Code Examples for javax.microedition.media.Manager#createPlayer()

The following examples show how to use javax.microedition.media.Manager#createPlayer() . 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: 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 3
Source File: Sound.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
public void init(int freq, long duration) {
	try {
		player = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
		state = SOUND_STOPPED;
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 4
Source File: Sound.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
public void init(byte[] data, int type) {
	try {
		player = Manager.createPlayer(new ByteArrayInputStream(data), "audio/midi");
		state = SOUND_STOPPED;
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 5
Source File: Clip.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
protected Player getPlayer() {
	Player player = null;
	try {
		if (data != null) {
			player = Manager.createPlayer(new ByteArrayInputStream(data), contentType);
		} else {
			player = Manager.createPlayer(str);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
	return player;
}
 
Example 6
Source File: AudioClip.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
public AudioClip(int type, java.lang.String filename) throws IOException {
	try {
		InputStream stream = ContextHolder.getResourceAsStream(null, filename);
		player = Manager.createPlayer(stream, "audio/midi");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 7
Source File: AudioClip.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
public AudioClip(int type, byte[] audioData, int audioOffset, int audioLength) {
	try {
		player = Manager.createPlayer(new ByteArrayInputStream(audioData), "audio/mmf");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 8
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 9
Source File: MediaRecorder.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
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 10
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 11
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 12
Source File: CodeScannerImpl.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void startScan() {
    try {
        System.gc();

        player = Manager.createPlayer("capture://video");
        player.realize();
        multimediaManager.setZoom(player);
        multimediaManager.setExposure(player);
        multimediaManager.setFlash(player);
        player.start();
        videoControl = (VideoControl) player.getControl("VideoControl");

        viewFinder = (Field) videoControl.initDisplayMode(
                VideoControl.USE_GUI_PRIMITIVE,
                "net.rim.device.api.ui.Field");

        if (videoControl != null) {
            viewFinderScreen = new ViewFinderScreen();
            UiApplication.getUiApplication().invokeLater(new Runnable() {

                public void run() {
                    UiApplication.getUiApplication().pushScreen(
                            viewFinderScreen);
                    viewFinder.setFocus();

                }
            });
            videoControl.setVisible(true);
            videoControl.setDisplayFullScreen(true);
            task = new BarcodeScanTask();
            // create timer every 3 seconds, get a screenshot
            timer = new Timer();
            timer.schedule(task, 0, 3000); // once every 3 seconds 
        } else {
            throw new MediaException("Video Control is not initialized");
        }
    } catch (Exception e) {
        callback.scanError(-1, e.getMessage());
    }
}
 
Example 13
Source File: PlayerPool.java    From pluotsorbet with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates and initializes the Player
 * 
 * @param sequence -
 *            tone sequence data in byte array
 * @return realized tone sequence Player
 * @throws MediaException
 *             thrown by the system while creating the player
 * @throws IOException
 *             thrown by the system while creating the player
 */
private Player createTonePlayer(byte[] sequence) throws MediaException, IOException {
    Player player = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
    player.addPlayerListener(this);
    player.realize();
    ToneControl tc = (ToneControl) (player.getControl("ToneControl"));
    tc.setSequence(sequence);
    return player;
}
 
Example 14
Source File: PlayerPool.java    From pluotsorbet with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates and initializes the Player.
 * 
 * @param media -
 *            Media datatype that represents the data
 * @return realized Player
 * @throws MediaException
 *             occured while creating the player
 * @throws IOException
 *             occured while creating the player
 */
private Player createPlayer(Media media) throws MediaException, IOException {
    InputStream is = media.getInputStream();
    String mediaType = media.getType();
    Player player = Manager.createPlayer(is, mediaType);
    player.addPlayerListener(this);
    player.realize();
    player.prefetch();
    return player;
}