Tuesday, 26 March 2019

How to get&modify metadata to supported audio files on Android?

Background

Android supports various audio files encoding and decoding.

I record audio into an audio file using android.media.MediaRecorder class, but I also wish to show information about the files I've recorded (not standard data, but still just text, maybe even configurable by user), and I think it's best to store this information within the files.

examples of possible data to store: when it was recorded, where it was recorded, notes by the user...

The problem

The MediaRecorder class doesn't have any function that I can find, to add or even read metadata of the recorded audio file.

I also can't find a similar class that does it.

What I've tried

I tried searching how to do it for specific files types, and also tried to find a library that does it.

I haven't find even a clue about this information.

The only thing I've found for MediaRecorder class, is a function called "setLocation" , which is used to indicate where the recording has started (geographically), and looking at its code, I can see it sets parameters:

public void setLocation(float latitude, float longitude) {
    int latitudex10000  = (int) (latitude * 10000 + 0.5);
    int longitudex10000 = (int) (longitude * 10000 + 0.5);

    if (latitudex10000 > 900000 || latitudex10000 < -900000) {
        String msg = "Latitude: " + latitude + " out of range.";
        throw new IllegalArgumentException(msg);
    }
    if (longitudex10000 > 1800000 || longitudex10000 < -1800000) {
        String msg = "Longitude: " + longitude + " out of range";
        throw new IllegalArgumentException(msg);
    }

    setParameter("param-geotag-latitude=" + latitudex10000);
    setParameter("param-geotag-longitude=" + longitudex10000);
}

But setParameter is private, and I'm not sure if it's ok to put anything I want into it, even if I had a way to access it (reflection, for example) :

private native void setParameter(String nameValuePair);

I also don't get, given an audio/video file, how to get/modify this kind of information. It's not available for SimpleExoPlayer, for example.

The questions

  1. How can I read,write, and modify metadata inside supported audio files of Android?

  2. Are there any limitations/restrictions for those actions?

  3. Which file formats are available for this?

  4. Is it possible to add the metadata while I record the audio?

  5. Is it possible perhaps via MediaStore ? But then how do I do those operations? And which files are supported? And does the metadata stay within the file?



from How to get&modify metadata to supported audio files on Android?

No comments:

Post a Comment