metadata.set(Metadata.CONTENT_TYPE, "audio/basic");
} else if (type == Type.WAVE) {
metadata.set(Metadata.CONTENT_TYPE, "audio/x-wav");
}
AudioFormat audioFormat = fileFormat.getFormat();
int channels = audioFormat.getChannels();
if (channels != AudioSystem.NOT_SPECIFIED) {
metadata.set("channels", String.valueOf(channels));
// TODO: Use XMPDM.TRACKS? (see also frame rate in AudioFormat)
}
float rate = audioFormat.getSampleRate();
if (rate != AudioSystem.NOT_SPECIFIED) {
metadata.set("samplerate", String.valueOf(rate));
metadata.set(
XMPDM.AUDIO_SAMPLE_RATE,
Integer.toString((int) rate));
}
int bits = audioFormat.getSampleSizeInBits();
if (bits != AudioSystem.NOT_SPECIFIED) {
metadata.set("bits", String.valueOf(bits));
if (bits == 8) {
metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "8Int");
} else if (bits == 16) {
metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "16Int");
} else if (bits == 32) {
metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "32Int");
}
}
metadata.set("encoding", audioFormat.getEncoding().toString());
// Javadoc suggests that some of the following properties might
// be available, but I had no success in finding any:
// "duration" Long playback duration of the file in microseconds
// "author" String name of the author of this file
// "title" String title of this file
// "copyright" String copyright message
// "date" Date date of the recording or release
// "comment" String an arbitrary text
for (Entry<String, Object> entry : fileFormat.properties().entrySet()) {
metadata.set(entry.getKey(), entry.getValue().toString());
}
for (Entry<String, Object> entry : audioFormat.properties().entrySet()) {
metadata.set(entry.getKey(), entry.getValue().toString());
}
} catch (UnsupportedAudioFileException e) {
// There is no way to know whether this exception was
// caused by the document being corrupted or by the format