Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
Expo Audio no deja de reproducirse en bucle

Estoy usando Expo-AV para reproducir un sonido cuando cargo la pantalla usando componentDidMount , dado que el audio no es muy largo, quiero reproducirlo en bucle hasta que el usuario presione un botón para detenerlo, el audio comienza correctamente pero cuando comienza para repetir el audio ya no se detiene.

(Tengo otra función en fetchNewOrder que necesito seguir ejecutando, por eso no quiero detener el intervalo)

Esta es la documentación que estoy siguiendo: 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 answers
Answer question

0

Para detener el bucle setInterval , debe llamar a clearInterval(idOfSetInterval) . setInterval devuelve una identificación.

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

updateTimer es una identificación y una llamada en stopSound clearInterval .

 stopSound = async () => { clearInterval(this.updateTimer) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!