1

So, i'm using this simple lines of code:

public static boolean checkIfAudioFileIsValid(String filePath) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    long duration;
    try {
        retriever.setDataSource(filePath);
        duration = Long.parseLong(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
    } catch (Exception e ) {
        return false;
    }
    return duration > 1000;
}

So i'm checking if file is valid and it's duration is more than one seconds. For the most part it's working right, BUT if file is empty or it's duration is below 400ms i'm getting same contant value 1520

Is there someone expirenced this issue and found how to solve it?

Nik Myers
  • 1,843
  • 19
  • 28
  • @pskink, no, i'm doing audio recording in the app programatically, just create EMPTY file with .ogg extention, and use it's path to this method – Nik Myers Mar 20 '17 at 11:49
  • @pskink, it might not work actually, i think it's better to attach file, wait a sec, it might be transcoding to ogg issue – Nik Myers Mar 20 '17 at 11:53
  • I record same `wav` and `amr` format audio, this function works fine, it always return the collect duration of the file. – Yu Jiaao Mar 20 '17 at 14:27
  • @YuJiaaoa and pksink , thank you both, but it still keep happening to me, i'm not sure about 400, maybe it's very short, something like 100, still, from your feedback i'm starting to think tha the issue is in my transcoding code(from PCM to OGG) – Nik Myers Mar 20 '17 at 14:35
  • did you do what i tried? – pskink Mar 20 '17 at 14:57
  • @pskink, i don't you that comment anymor for some reason – Nik Myers Mar 20 '17 at 15:02

0 Answers0