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

📄 ueberdosismp3taginfo.java

📁 eclise rcp 项目,是非常好的学习源码
💻 JAVA
字号:
package com.siemens.ct.mp3m.model.ueberdosis;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

import com.siemens.ct.mp3m.model.IMP3Info;
import com.siemens.ct.mp3m.utilities.LogUtil;

import de.ueberdosis.mp3info.ExtendedID3Tag;
import de.ueberdosis.mp3info.ID3Reader;
import de.ueberdosis.mp3info.ID3Tag;
import de.ueberdosis.mp3info.ID3Writer;

public class UeberdosisMP3TagInfo implements IMP3Info {
    private ExtendedID3Tag id3;

    private String mp3FilePath;

    public String getTitle() {
        return id3.getTitle();
    }

    public String getArtist() {
        return id3.getArtist();
    }

    public String getAlbum() {
        return id3.getAlbum();
    }

    public String getYear() {
        if (id3.getYear() == null)
            return ""; //$NON-NLS-1$
        return id3.getYear();
    }

    public String getTrack() {
        if (id3.getTrack() == 0)
            return ""; //$NON-NLS-1$
        return id3.getTrackS();
    }

    public String getGenre() {
        try {
            // Bug in taglib
            if (id3.getGenre() == 126)
                return ""; //$NON-NLS-1$
            return id3.getGenreS();
        } catch (RuntimeException e) {
            // Ignore, might be indexOutOfBounds Exception
        }
        return ""; //$NON-NLS-1$
    }

    public String getComment() {
        return id3.getComment();
    }

    public int getDuration() {
        return id3.getRuntime();
    }

    public int getSize() {
        return (int) id3.getSize();
    }

    public String getBitrate() {
        return id3.getBitrateS();
    }

    public String getFrequency() {
        return id3.getFrequencyS();
    }

    public void setMP3File(String fullPath) {
        mp3FilePath = fullPath;
        try {
            UeberdosisId3Reader id3Reader = new UeberdosisId3Reader(fullPath);
            id3 = id3Reader.getExtendedID3Tag();
        } catch (IOException e) {
        	LogUtil.logError("com.siemens.ct.mp3m.model.ueberdosis",e);
        }
    }

    public String getMP3File() {
        return mp3FilePath;
    }

    public void saveMP3File() {
        try {
            RandomAccessFile file = new RandomAccessFile(mp3FilePath, "rw"); //$NON-NLS-1$
            ID3Writer.writeTag(file, id3);
            file.close();
        } catch (FileNotFoundException e) {
        	LogUtil.logError("com.siemens.ct.mp3m.model.ueberdosis",e);
        } catch (IOException e) {
        	LogUtil.logError("com.siemens.ct.mp3m.model.ueberdosis",e);
        }
    }

    public void setTitle(String title) {
        id3.setTitle(title);
    }

    public void setArtist(String artist) {
        id3.setArtist(artist);
    }

    public void setAlbum(String album) {
        id3.setAlbum(album);
    }

    public void setYear(String year) {
        id3.setYear(year);
    }

    public void setTrack(String track) {
        int t = 0;

        try {
            t = Integer.parseInt(track);
        } catch (NumberFormatException e) {
            // ignore
        }

        id3.setTrack(t);
    }

    public void setGenre(String genre) {
        byte b = 0;
        for (String g : ID3Tag.genres) {
            if (g.equalsIgnoreCase(genre)) {
                id3.setGenre(b);
                return;
            }
            b += 1;
        }
        id3.setGenre(126);
    }

    public void setComment(String comment) {
        id3.setComment(comment);
    }
}

class UeberdosisId3Reader extends ID3Reader {

    public UeberdosisId3Reader(String arg0) throws IOException {
        super(arg0);
    }

    public boolean checkVBR(RandomAccessFile arg0) throws IOException {
        return false;
    }

}

⌨️ 快捷键说明

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