* @Author: Denis Tulskiy
* @Date: 26.06.2009
*/
public class FLACFileReader extends AudioFileReader {
public Track readSingle(Track track) {
TrackData trackData = track.getTrackData();
try {
/*if (Util.getFileExt(trackData.getFile()).equalsIgnoreCase("oga")) {
OggFlacDecoder dec = new OggFlacDecoder();
dec.open(new RandomAccessFile(trackData.getFile(), "r"));
StreamInfo streamInfo = dec.getStreamInfo();
trackData.setSampleRate(streamInfo.getSampleRate());
trackData.setBps(streamInfo.getBitsPerSample());
trackData.setChannels(streamInfo.getChannels());
trackData.setTotalSamples(streamInfo.getTotalSamples());
for (Metadata m : dec.getMetadata()) {
if (m instanceof VorbisComment) {
VorbisComment comment = (VorbisComment) m;
VorbisCommentTag vorbisTag = new VorbisCommentTag();
HashMap<String, String> map = comment.getComments();
for (String key : map.keySet()) {
try {
VorbisCommentFieldKey newKey = VorbisCommentFieldKey.valueOf(key);
vorbisTag.add(vorbisTag.createTagField(newKey, map.get(key)));
} catch (IllegalArgumentException e) {
vorbisTag.add(vorbisTag.createTagField(key, map.get(key)));
}
}
copyCommonTagFields(vorbisTag, track);
}
}
} else*/ {
FlacFileReader reader = new FlacFileReader();
AudioFile af1 = reader.read(trackData.getFile());
Tag tag = af1.getTag();
copyCommonTagFields(tag, track);
copySpecificTagFields(tag, track);
GenericAudioHeader audioHeader = (GenericAudioHeader) af1.getAudioHeader();
copyHeaderFields(audioHeader, track);
}
} catch (Exception e) {
System.out.println("Couldn't read file: " + trackData.getFile());
}
return track;
}