wheat32
wheat32

Reputation: 21

Java: Getting the metadata tags from a wave audio file

I've exported a wave (.wav) file from Audacity with custom tags in the metadata with the keys: LOOP_START and LOOP_LENGTH.

Screenshot of the tags in the metadata editor in Audacity

My only problem is I don't know how to get the values attached to these keys in my Java program. How would I go about this?

Edit: I would prefer using a solution using the standard Java libraries, although I wouldn't be opposed to downloading a 3rd party library if it is the only way.

Edit2: Here is some code I am messing around with:

URL url = Main.class.getClassLoader().getResource("bgm/bgm4.wav");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
AudioFormat format = audioInputStream.getFormat();
System.out.println(format.properties());

but that only prints this: "{}". ("bgm" is a folder (the direct child of src))

I know that it is reading the file because it isn't throwing any exceptions, but it is going to the bin from the root, not the src. I'm not sure if that makes a difference. But the audio file in the bin has the same metadata tags as the one in the src.

1/13/18 Edit: Still trying to get this answered. Here is some new code I'm trying:

URL url = AudioMetadata.class.getClassLoader().getResource("audio/bgm4.wav");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
AudioFormat format = audioInputStream.getFormat();
AudioFileFormat fformat = AudioSystem.getAudioFileFormat(url);

Map<String, Object> props = fformat.properties();
System.out.println(props.size());

This prints: 0.

Upvotes: 2

Views: 3205

Answers (1)

arkdevelopment
arkdevelopment

Reputation: 167

You should be able to use the Java Sound library and the .properties aspect of it once the .wav is read in. Here is a link to the Java Sound guide.

Ex.

AudioFormat file = stream.getFormat();
System.out.println("Properties: " + file.properties());

Upvotes: 1

Related Questions