⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manager.java

📁 J2me唆哈的代码
💻 JAVA
字号:
/*
 * Created on 2005-9-27 by pcy
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package javax.microedition.media;

import java.io.*;

import a.a.a.mmedia.*;

public final class Manager {

    public static final String TONE_DEVICE_LOCATOR = "device://tone";


    native private static int nPlayTone(int note, int  dur, int vol);

    private Manager() {}

    public static String [] getSupportedContentTypes(String protocol) {
        if (protocol == null){
            return new String [] { "audio/x-wav", "audio/x-tone-seq" };
        }
        if (protocol.equals("device")){
            return new String [] { "audio/x-tone-seq" };
        }
        if (protocol.equals("http")){
            return new String [] { "audio/x-wav" };
        }
        return new String[0];
    }

    
    public static String [] getSupportedProtocols(String content_type) {
        if (content_type == null){
            return new String [] { "device", "http" };
        }
        if (content_type.equals("audio/x-tone-seq")){
            return new String [] { "device" };
        }
        if (content_type.equals("audio/x-wav")){
            return new String [] { "http" };
        }
        return new String[0];
    }

    
    public static Player createPlayer(String locator) throws IOException, MediaException {

        if (locator == null){
            throw new IllegalArgumentException("locator: null");
        }    
        BasicPlayer p = null;
        boolean conn = true;
        if (locator.equals(TONE_DEVICE_LOCATOR)) {
            p = new TonePlayer();
            conn = false;
        } else {
            if (locator.toLowerCase().endsWith(".wav")
                    ||locator.startsWith("http:")) {
                p = new WavPlayer();
            }else if (locator.toLowerCase().endsWith(".mid")
                    ||locator.toLowerCase().endsWith(".midi")
                    ||locator.startsWith("http:")) {
                p = new MidiPlayer();
            }
        }    
        if (p == null){
            throw new MediaException("Unsupported type.");
        }        
        p.setLocator(locator, conn);
        
        return p;
    }

    
    public static Player createPlayer(InputStream stream, String type) throws IOException, MediaException {
        if (stream == null){
            throw new IllegalArgumentException("stream: null");
        }
        BasicPlayer p = null;
    
        if (type != null) {
            type = type.toLowerCase();
        }
        if ((type == null) 
                ||((type != null) && (type.equals("audio/x-wav")))) {
            p = new WavPlayer();
        }
    
        if ((type != null) && (type.equals("audio/x-tone-seq"))) {
            p = new TonePlayer();
        }
        
        if ((type != null) && (type.equals("audio/midi"))) {
            p = new MidiPlayer();
        }
    
        if (p != null) {
            p.setStrm(stream);
            p.setLocator(null, false);
            return p;
        } 
        throw new MediaException("Unsupported type.");
    }

    
    static public void playTone(int note,
                int duration,
                int volume)throws MediaException {
        if (note < 0 || note > 127 || duration <= 0){
            throw new IllegalArgumentException("playTone");
        }
    
        if (nPlayTone(note, duration, volume) <= 0){
            throw new MediaException("can't play tone");
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -