What is the unit of measurment for media duration in MediaMetadataRetriever

android, duration, media, metadata

Solution

See this

  long durationMs = Long.parseLong(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
                    long duration = durationMs / 1000;
                    long h = duration / 3600;
                    long m = (duration - h * 3600) / 60;
                    long s = duration - (h * 3600 + m * 60);
                    String durationValue;
                    if (h == 0) {
                       durationValue = String.format(
                       activity.getString(R.string.details_ms), m, s);
                       } else {
                            durationValue = String.format(
                            activity.getString(R.string.details_hms), h, m, s);
                         }
                    }  

Problem

One can use ``` String MediaMetadataRetriver.extractMetadata(int key); ``` with ``` key = MediaMetadataRetriver.METADATA_KEY_DURATION ``` to extract the media duration. This function returns a String, but there is no documentation regarding the format or unit of measurement this string represents. I would assume it is an integer in ms, but the rest of MediaMetadataRetriever's apis uses us. So what is the unit for duration? Do you think the lack of specification is intentional or a bug?

Original source