FileDocCategorySizeDatePackage
Manager.javaAPI DocphoneME MR2 API (J2ME)6743Wed May 02 18:00:46 BST 2007javax.microedition.media

Manager

public final class Manager extends Object
This class is defined by the JSR-135 specification Mobile Media API, Version 1.2.

Fields Summary
private static com.sun.mmedia.Configuration
config
private static com.sun.mmedia.TonePlayer
tonePlayer
private static Object
createLock
public static final String
TONE_DEVICE_LOCATOR
private static final String
DS_ERR
private static final String
PL_ERR
private static final String
REDIRECTED_MSG
Constructors Summary
private Manager()
This private constructor keeps anyone from actually getting a Manager.



                   
       
Methods Summary
public static PlayercreatePlayer(java.lang.String locator)


        if (locator == null) {
            throw new IllegalArgumentException();
        }

        String locStr = locator.toLowerCase();
        String validLoc;
	
        if (locStr.equals(validLoc = TONE_DEVICE_LOCATOR)) {
                
            ABBBasicPlayer p;
            
            // separate device & encodings
            int encInd = locator.indexOf('?");
            String encStr = null;
            if (encInd > 0) {
                encStr = locator.substring(encInd + 1);
                locStr = locStr.substring(0, encInd);
                /* 
                 * TBD: check case when '?' is the last Locator symbol:
                 *Will encStr be == "", or it will be == null ?
                 */
            } else {
                /*
                 * detect invalid locator case: 
                 * if no '?' found then locStr & validLoc shall be 
                 * equivalent strings, but since they have already passed 
                 * char-to-char comparison, we to check lengths only...
                 */
                if (locStr.length() != validLoc.length())
                    throw new MediaException("Malformed locator");
                encStr = "";
            }
            String className = config.getHandler(locStr);
            try {
                // Try and instance the player ....
                Class protoClass = Class.forName(className);
                p = (ABBBasicPlayer) protoClass.newInstance();
                // Pass encStr to created Player as argument
                if (!p.initFromURL(encStr)) {
                    throw new MediaException("Invalid locator media encodings");
                };
                //System.out.println("DEBUG: Manager.createPlayer(" + locator + ") returned#1 " + p);
                return p;
            } catch (Exception e) {
                throw new MediaException(PL_ERR + locator + 
                        REDIRECTED_MSG + e.getMessage());
            }
        } else { 
            // not in the list of predefined locators, 
            // find handler by extension

            String theProtocol = null;
            int idx = locStr.indexOf(':");

            if (idx != -1) {
                theProtocol = locStr.substring(0, idx);
            } else {
                throw new MediaException("Malformed locator");
            }

            String[] supported = getSupportedProtocols(config.ext2Mime(locStr));
            boolean found = false;
            for (int i = 0; i < supported.length; i++) {
                if (theProtocol.equals(supported[i])) {
                    found = true;
                    break;
                }
            }

            if (!found) {
                throw new MediaException(PL_ERR + locator);
            }

            Player pp = null;

            throw new MediaException("Not supported");
            
            //System.out.println("DEBUG: Manager.createPlayer(" + locator + ") returned#2 " + pp);
            // return pp;
        }
    
public static PlayercreatePlayer(java.io.InputStream stream, java.lang.String type)

        
        if (stream == null) {
            throw new IllegalArgumentException();
        }

        if (type == null) {
            throw new MediaException(PL_ERR + "NULL content-type");
        }

        throw new MediaException("Not supported");
    
public static java.lang.String[]getSupportedContentTypes(java.lang.String protocol)

        return config.getSupportedContentTypes(protocol);        
    
public static java.lang.String[]getSupportedProtocols(java.lang.String content_type)

        return config.getSupportedProtocols(content_type);
    
public static voidplayTone(int note, int duration, int volume)

        
        if (note < 0 || note > 127 || duration <= 0) {
            throw new IllegalArgumentException("bad param");
        }

        if (duration == 0 || volume == 0) {
            return;
        }

        synchronized(createLock) {
            if (tonePlayer == null) {
                tonePlayer = config.getTonePlayer();
            }
        }
        
        if (tonePlayer != null) {
            tonePlayer.playTone(note, duration, volume);
        } else {
            throw new MediaException("no tone player");
        }