Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
Expo Audio won't stop looping

I'm using Expo-AV to play a sound when I load the screen using componentDidMount, since the audio isn't very long I want to loop it until the user presses a button to stop it, the audio starts correctly but when it starts to loop the audio doesn't stop anymore.

(I have another function in fetchNewOrder which I need to keep running, that's why I don't want to stop the interval)

This is the documentation I'm following: https://docs.expo.dev/versions/v44.0.0/sdk/av/

export class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      sound: null,
    };
  }

  async componentDidMount() {
    this.updateTimer = setInterval(() => {
      this.fetchNewOrders();
      }, 10000);
  }


  fetchNewOrders = async () => {
     const { sound } = await Audio.Sound.createAsync(require('../../../assets/ringtone2.mp3'));
       this.setState({sound: sound});
       this.playSound()
  }

  playSound = async () => {
      await this.state.sound.playAsync()
      await this.state.sound.setIsLoopingAsync(true)
  };

  stopSound = async () => {
    await this.state.sound.stopAsync()
    await this.state.sound.unloadAsync()
  }


render() {
  return(
    <View>  
      <Button
        onPress={this.stopSound}
      />
    </View>
   )
 }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To stop the setInterval loop, you have to call clearInterval(idOfSetInterval). setInterval returns an id.

this.updateTimer = setInterval(() => {
      this.fetchNewOrders();
      }, 10000);

console.log(this.updateTimer)

updateTimer is an id an in stopSound call clearInterval.

stopSound = async () => {
    clearInterval(this.updateTimer)
  }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda