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

📄 mpeginfo.java

📁 YOYOPlayer MP3播放器 java+JMF实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }else{            return source;        }    }    private void readHead() {        this.total = header.getTrackLength();    }    /**     * Load info from AudioFileFormat.     *     * @param aff     */    protected void loadInfo(AudioFileFormat aff) throws UnsupportedAudioFileException {        String tp = aff.getType().toString();        System.out.println("format:" + aff.getType().getExtension());        if (!tp.equalsIgnoreCase("mp3")) {            throw new UnsupportedAudioFileException("Not MP3 audio format");        }        if (aff instanceof TAudioFileFormat) {            Map props = ((TAudioFileFormat) aff).properties();            if (props.containsKey("mp3.channels")) {                channels = ((Integer) props.get("mp3.channels")).intValue();            }            if (props.containsKey("mp3.frequency.hz")) {                rate = ((Integer) props.get("mp3.frequency.hz")).intValue();            }            if (props.containsKey("mp3.bitrate.nominal.bps")) {                nominalbitrate = ((Integer) props.get("mp3.bitrate.nominal.bps")).intValue();            }            if (props.containsKey("mp3.version.layer")) {                layer = "Layer " + props.get("mp3.version.layer");            }            if (props.containsKey("mp3.version.mpeg")) {                version = (String) props.get("mp3.version.mpeg");                if (version.equals("1")) {                    version = "MPEG1";                } else if (version.equals("2")) {                    version = "MPEG2-LSF";                } else if (version.equals("2.5")) {                    version = "MPEG2.5-LSF";                }            }            if (props.containsKey("mp3.mode")) {                int mode = ((Integer) props.get("mp3.mode")).intValue();                if (mode == 0) {                    channelsMode = "Stereo";                } else if (mode == 1) {                    channelsMode = "Joint Stereo";                } else if (mode == 2) {                    channelsMode = "Dual Channel";                } else if (mode == 3) {                    channelsMode = "Single Channel";                }            }            if (props.containsKey("mp3.crc")) {                crc = ((Boolean) props.get("mp3.crc")).booleanValue();            }            if (props.containsKey("mp3.vbr")) {                vbr = ((Boolean) props.get("mp3.vbr")).booleanValue();            }            if (props.containsKey("mp3.copyright")) {                copyright = ((Boolean) props.get("mp3.copyright")).booleanValue();            }            if (props.containsKey("mp3.original")) {                original = ((Boolean) props.get("mp3.original")).booleanValue();            }            emphasis = "none";            if (props.containsKey("title")) {                title = (String) props.get("title");                title = toGBK(title);            }            if (props.containsKey("author")) {                artist = (String) props.get("author");                artist = toGBK(artist);            }            if (props.containsKey("album")) {                album = (String) props.get("album");                album = toGBK(album);            }            if (props.containsKey("date")) {                year = (String) props.get("date");            }            if (props.containsKey("duration")) {                total = (long) Math.round((((Long) props.get("duration")).longValue()) / 1000000);            }            if (props.containsKey("mp3.id3tag.genre")) {                genre = (String) props.get("mp3.id3tag.genre");                genre = toGBK(genre);            }            if (props.containsKey("mp3.id3tag.track")) {                try {                    track = ((String) props.get("mp3.id3tag.track"));                } catch (NumberFormatException e1) {                    // Not a number                }            }        }    }    private String toGBK(String s) {//        return s;        try {            return new String(s.getBytes("iso8859-1"), Config.getConfig().getEncoding());        } catch (Exception ex) {            Logger.getLogger(MpegInfo.class.getName()).log(Level.SEVERE, null, ex);            return s;        }    }    /**     * Load MP3 info from URL.     *     * @param input     * @throws IOException     * @throws UnsupportedAudioFileException     */    protected void loadInfo(URL input) throws IOException, UnsupportedAudioFileException {        AudioFileFormat aff = AudioSystem.getAudioFileFormat(input);        loadInfo(aff);        loadShoutastInfo(aff);    }    /**     * Load Shoutcast info from AudioFileFormat.     *     * @param aff     * @throws IOException     * @throws UnsupportedAudioFileException     */    protected void loadShoutastInfo(AudioFileFormat aff) throws IOException, UnsupportedAudioFileException {        String tp = aff.getType().toString();        if (!tp.equalsIgnoreCase("mp3")) {            throw new UnsupportedAudioFileException("Not MP3 audio format");        }        if (aff instanceof TAudioFileFormat) {            Map props = ((TAudioFileFormat) aff).properties();            // Try shoutcast meta data (if any).            Iterator it = props.keySet().iterator();            comments = new Vector();            while (it.hasNext()) {                String key = (String) it.next();                if (key.startsWith("mp3.shoutcast.metadata.")) {                    String value = (String) props.get(key);                    key = key.substring(23, key.length());                    if (key.equalsIgnoreCase("icy-name")) {                        title = value;                    } else if (key.equalsIgnoreCase("icy-genre")) {                        genre = value;                    } else {                        comments.add(key + "=" + value);                    }                }            }        }    }    public boolean getVBR() {        return vbr;    }    public int getChannels() {        return channels;    }    public String getVersion() {        return version;    }    public String getEmphasis() {        return emphasis;    }    public boolean getCopyright() {        return copyright;    }    public boolean getCRC() {        return crc;    }    public boolean getOriginal() {        return original;    }    public String getLayer() {        return layer;    }    public long getSize() {        return size;    }    public String getLocation() {        return location;    }    /*-- TagInfo Implementation --*/    public int getSamplingRate() {        return rate;    }    public int getBitRate() {        return nominalbitrate;    }    public long getPlayTime() {        return total;    }    public String getTitle() {        return title;    }    public String getArtist() {        return artist;    }    public String getAlbum() {        return album;    }    public String getTrack() {        return track;    }    public String getGenre() {        return genre;    }    public Vector getComment() {        return comments;    }    public String getYear() {        return year;    }    public String getType() {        return type;    }    /**     * Get channels mode.     *     * @return channels mode     */    public String getChannelsMode() {        return channelsMode;    }    public static void main(String[] args) throws Exception {        MpegInfo info = new MpegInfo();//        info.load(new File("D:\\有没有人告诉你.mp3"));        info.load(new URL("http://zhengfu.dx.comenic.com/mzju-gov-b/admingly/movie/2007103014045.mp3"));        Class c = info.getClass();        Method[] ms = c.getMethods();        for (Method m : ms) {            if (m.getName().startsWith("get")) {                Object obj = m.invoke(info);                System.out.println(m.getName() + ":" + obj);            }        }    }}

⌨️ 快捷键说明

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