I am creating a m4a file with MediaRecorder as follows:
recorder2 = new MediaRecorder();
recorder2.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder2.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder2.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder2.setAudioEncodingBitRate(128000);
recorder2.setAudioSamplingRate(44100);
recorder2.setOutputFile(<fullFilePath.m4a>);
It works perfectly. After the file is created, I want to add ID3 tags to it using jaudiotagger. So I do:
AudioFile f = AudioFileIO.read(new File(<fullFilePath.m4a>));
Tag fileTag = f.getTag();
fileTag.setField(FieldKey.COMMENT,"AVE Tags:.....");
This is working great with WAV files generated with AudioRecord, but for m4a files generated as above with MediaRecorder I get an exception in the AudioFile line:
W/System.err: org.jaudiotagger.audio.exceptions.CannotReadException: <fullFilePath.m4a>:
Unable to find next atom because identifier is invalid ��������
I also tried with
Mp4FileReader reader = new Mp4FileReader();
AudioFile f = reader.read(new File(AveActivity.REC_DIR,song));
....
but I get the same error... What's wrong?
BTW, I am using implementation 'com.github.goxr3plus:jaudiotagger:2.2.7' (Why so many versions? Isn't this quite dangerous??)
EDIT:
There are several things that I do not like about this, so I decided to ditch jaudiotagger
altogether. It doesn't make sense to use this heavy, buggy, and hard-to-track-a-trusty-version of it for android. So I made my own tiny thing here for WAVE files that works perfectly right after AudioRecord
, and without the need to open/close/save the file twice.
Yet, I am not deleting the post since the first half shows that there is something strange with jaudiotagger
for m4a, at least with the version I got from goxr3plus
.