expo-av Audio dependencie fails sometimes when is used a lot of times

Please provide the following:

  1. SDK Version: 43.0.0
  2. Platforms(Android/iOS/web/all): Android
  3. Add the appropriate “Tag” based on what Expo library you have a question on.
const audios = {
  beep: require("../assets/sounds/beepSound.mp3"),
  error: require("../assets/sounds/errorSound.mp3"),
  repeated: require("../assets/sounds/qrRepeated.mp3"),

import * as React from "react";
import { Audio } from "expo-av";

const useSound = () => {
  const playSound = React.useCallback(async (soundName) => {
    const sound = new Audio.Sound();
    try {
      await sound.loadAsync(audios[soundName]);
      await sound.playAsync(); // Here is the problem
      await sleep(1000);
      // Your sound is playing!
      // Don't forget to unload the sound from memory
      // when you are done using the Sound object
      await sound.unloadAsync();
    } catch (error) {
      // An error occurred!
  }, []);

  return { playSound };
export default useSound;

I have this code to play a beep sound each time a qr is written with my app, at first it works totally fine, but after playing the sound for aroun 20 times it suddenly stop working, I’m not sure what might be, any idea?

Hey @sebas0811buitrago, when you load a Sound object, you will also need to unload it using unloadAsync, otherwise it will not be cleaned up and you will run out of memory.

Can you try using setOnPlaybackStatusUpdate() and see if the playback suddenly stops. An example of how to use it and unload the sound can be found in this GitHub issue comment.

1 Like

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