循环进入Expo React Native

时间:2019-10-13 05:05:31

标签: react-native expo

我想播放音频一段时间。无论如何,您是否可以确定循环音频的时间?在博览会上,我只看到声音的状态:isLooping:true。这将使声音无限循环,而不是一定时间!下面是我关于声音状态和播放声音的代码

//state of the sound
const { sound, status } = await this.recording.createNewLoadedSoundAsync(
      {
        isLooping: false,
        isMuted: this.state.muted,
        volume: this.state.volume,
        rate: this.state.rate,
        shouldCorrectPitch: this.state.shouldCorrectPitch
      },
      this._updateScreenForSoundStatus
    );

//play sound or pause sound when the button is pressed
_onPlayPausePressed = () => {
    if (this.sound != null) {
      if (this.state.isPlaying) {
        this.sound.pauseAsync();
      } else {
        this.sound.playAsync();
      }
    }
  };

1 个答案:

答案 0 :(得分:1)

请查看this,它说明了如何精确地循环20次。

希望这会有所帮助!