[Audio] How to update state continuously?


I want to play a sound and display a bar that fills itself as the time passes. This happens in the official unofficial repo with the complete Audio API, that most of us use here. That repo, uses the ancient hidden function below:

await this.recording.createNewLoadedSoundAsync(options, _updateScreenForSoundStatus)

I cannot find anything about createNewLoadedSoundAsync online although that’s not the problem. The problem is that _updateScreenForSoundStatus is called every second or something (usually a little less than that). I want something that gets called much more often to provide a smooth experience for the bar I mentioned earlier.

I tried increasing the frequency by using setInterval, like this:

this.interval = setInterval(() => {
        const value = (this.state.soundPosition/this.state.soundDuration*360)/180*Math.PI
        const cos = Math.cos(value)
        const sin = Math.sin(value)
        console.log('value: ' + value)
        this.setState({ cos: cos, sin: sin })}, 20);


However the this.state.soundPosition doesn’t get updated often, so I am guessing this is the root of the problem. Any help on how to procede?



closed #3

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