Java Code Examples for javax.microedition.media.Player#realize()

The following examples show how to use javax.microedition.media.Player#realize() . 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: 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 4
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 5
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 6
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;
}