播放Native / Expo AV中断声音

时间:2020-02-08 01:00:47

标签: javascript reactjs react-native expo

开发一个播放列表应用,该应用必须制作API并在播放它们之间检索歌曲数据。歌曲会加载并播放,但是,如果用户要向“下一个”按钮发送垃圾邮件,它通常会加载多个实例,从而使它们相互叠加播放。

我认为问题在于当另一首歌曲仍在加载时选择了新歌。有没有办法创建更具中断性的功能?

static void f<T>() where T : class
{
    T t = default;
    Console.WriteLine(t);
}

在山上

    this.activeAudio = null
    this.state = {
      activeSection: 0,
      volume: 1,
      rate: 1.0
    }

更改事件中

  async componentDidMount() {
    Audio.setAudioModeAsync({
      allowsRecordingIOS: false,
      interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
      playsInSilentModeIOS: true,
      shouldDuckAndroid: true,
      interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
      staysActiveInBackground: true,
      playThroughEarpieceAndroid: true
    })
    await this.loadNewSong(true)
  }

歌曲更改

changeSong = (index) => {
    const currentIndex = this.state.activeSection
    if (index !== currentIndex) {
      this.setState({ activeSection: index }, () => this.loadNewSong(true))
    }
  }

0 个答案:

没有答案