0

I am new to React-Native. And am trying to develop an Audio App, where the user should be able to click on any Audio from a list, and that Audio should Play onPress()

Here is my code

sound = new Sound('http://example.com/xyz.mp3');

playSound ()  {
    this.sound.play();
};

pauseSound () {
    this.sound.pause();
};

playFile (x1) {

    sound = new Sound(x1);
    this.playSound();

}

When I call playFile(x1) with a new file name x1, it gives error:

Attempted to assign to readonly property.

Is there a wayto reassign a new value to the sound variable onPress? Or any other simple solution to this issue of reassignment?

AnR
  • 1,809
  • 3
  • 26
  • 45

1 Answers1

0

Found a solution myself.

if you use sound.release() before assigning a new file, it works.

It allows you to re-assign a new file. Hence the code will be like this:

sound.release();
sound = new Sound(x1);
AnR
  • 1,809
  • 3
  • 26
  • 45