Incorrect durationMillis from setOnRecordingStatusUpdate

I’m creating an iOS app where users can record their voices and want to have UI which shows the duration of recordings. Thus, I have used setOnRecordingStatusUpdate and set the updateInterval as 100 milliseconds. However, the durations I got are incorrect as the following pic shows (suddenly big numbers come out). This not always but sometimes happens. How do I solve this problem?

My environment and code are below.

  1. SDK Version: 33.0.0
  2. Platforms: iOS
  const [recordingDuration, updateRecordingDuration] = useState(0)
  const updateInterval = 100


  const beginRecording = async () => {
    await Audio.setAudioModeAsync({
      allowsRecordingIOS: true,
      interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_MIX_WITH_OTHERS,
      playsInSilentModeIOS: true,
      shouldDuckAndroid: true,
      interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
      playThroughEarpieceAndroid: true,
      staysActiveInBackground: false,
    })

    const recording = new Audio.Recording()
    const recordingSettings = JSON.parse(JSON.stringify(Audio.RECORDING_OPTIONS_PRESET_LOW_QUALITY))
    recordingInstanceRef.current = recording
    recordingInstanceRef.current.setOnRecordingStatusUpdate(updateRecordingStatus)
    recordingInstanceRef.current.setProgressUpdateInterval(updateInterval)
    await recordingInstanceRef.current.prepareToRecordAsync(recordingSettings)
      .then((res) => {
        if (res.canRecord && !isBreakRef.current) {
          recordingInstanceRef.current.startAsync()
        } 
      })
  }

  const updateRecordingStatus = (status) => {
    if (status.isRecording) {
      console.log(status)
      updateRecordingDuration(status.durationMillis)
    } else if (status.isDoneRecording) {
      updateRecordingDuration(0)
    }
   }

  const stopRecording = async () => {
    try {
      await recordingInstanceRef.current.stopAndUnloadAsync()
    } catch (e) {
      console.log(e)
    }
    await Audio.setAudioModeAsync({
      allowsRecordingIOS: false,
      interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_MIX_WITH_OTHERS,
      playsInSilentModeIOS: false,
      shouldDuckAndroid: true,
      interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
      playThroughEarpieceAndroid: true,
      staysActiveInBackground: false,
    })
    recordingInstanceRef.current.setOnRecordingStatusUpdate(null)
    recordingInstanceRef.current = null
  }
1 Like

Hey @takuya0206,

Would you be able to create a Github Issue with as much relevant information and a reproducible example, if possible in the form of a Snack, so we can track this properly?

Cheers,
Adam

Thank you for your suggestion. However, after upgrading SDK 35, this problem has never happened. So I will close this.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.