Audio.Sound has Array with many undefined


#1

I am trying to use Audio at certain times throughout my app.

  • When the app Loads
  • When a new Level is loaded
  • When A button is pressed
  • When a word is correct
  • When A Level is completed.

For each instance, I have declared a new exp.audio.sound object. It works fine through the first ten or so levels. Then each sound one by one stops working until no sound is working at all.

here is a example of how Iam using it

import { Audio } from ‘expo’;
import click from ‘…/assets/sounds/Tiny-Button.mp3’;
import new_board from ‘…/assets/sounds/new_board.mp3’;
import correct from ‘…/assets/sounds/correct.mp3’;

constructor(props) {
clicksfx = new Audio.Sound();
correctsfx = new Audio.Sound();
new_boardsfx = new Audio.Sound();

this.state = {
clicksfx,
coreectsfx,
new_boardsfx,
};
}

async clickButton() {
const soundObject = this.state.clicksfx;
const sndsOBJ = await soundObject.getStatusAsync();
try {
if (!sndsOBJ.isLoaded) {
await soundObject.loadAsync(new_board);
await soundObject.playAsync();
} else {
await soundObject.replayAsync();
}
} catch (error) {
console.log(error);
}
}

async componentWillUnmount() { 
    const { clicksfx, coreectsfx, new_boardsfx } = this.state; 
    try { 
        await clicksfx.unloadAsync();
        await coreectsfx.unloadAsync();
        await new_boardsfx.unloadAsync();
    } catch (error) {
        console.log(error);
    }
 }    

I console logged one of the sound objects And found that it’s being filled with undefines every time I use it no matter what instance I am using.
“didCompleteNetworkResponse”: Array [
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
],
“didReceiveNetworkData”: Array [
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
],
“didReceiveNetworkDataProgress”: Array [
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
],
“didReceiveNetworkIncrementalData”: Array [
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
],
“didReceiveNetworkResponse”: Array [
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
],
“didSendNetworkData”: Array [
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
],
And it grows to a point were one array could have over 100 undefined
I am at a lost. I don’t know If I am using it incorrectly or not.
Any help will be well appreciated.


closed #2

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