react-native-sound: getDuration() not working

I am trying to use getDuration() to determine when the user is at the end of their playback, but it is returning incorrect values. For example I have a 7 minute 12 second recording for which it should be returning something in the vicinity of 432 seconds, but it is currently returning approximately 410.5. This is on iOS, have not tested on Android. I know for sure the recording is 7 minutes and 12 seconds because I can sit there and listen to it, and watch the timer based on getCurrentTime() count all the way up…

EDIT: To add some more context for this, I was playing an .aac audio file recorded using the package react-native-audio

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 3
  • Comments: 15 (2 by maintainers)

Most upvoted comments

I have this issue on Android. It works fine on iOS, but on Android the call to getDuration() is returning -0.001 seconds. Any idea why?

Seems it is still not resolved

+1

I’m also experiencing an issue where getDuration() is not returning the correct length of an aac file recorded with react-native-audio.

  loadRecording() {
    let recordingFilePath = AudioUtils.DocumentDirectoryPath + "/" + this.props.recording.filename;
    let soundFile = new Sound(recordingFilePath, '', (error) => {
      if (error) {
        console.log('failed to load the sound', error);
        return;
      }
      // loaded successfully
      console.log('duration in seconds: ' + soundFile.getDuration() + ', number of channels: ' + soundFile.getNumberOfChannels());
    });
  }

I am having this same issue, I am using react-native-audio lib to record the audio. This is my audio config:

    SampleRate: 22050,
    Channels: 1,
    AudioQuality: "Low",
    AudioEncoding: "aac",
    AudioEncodingBitRate: 32000

Audio recorded in android device works fine in both android and iOS devices, able to get duration for them. Audio recorded from iOS device works fine iOS device, but for same iOS recorded audio, I am not able to get duration while playing that in android(it give -0.001 seconds duration, which is default). Any idea how to solve this? Help appreciated. Thanks.