Check out example codes for "java android play sound file with variable". It will help you in understanding the concepts better.

Code Example 1

private void playMp3(String nameOfFile){
   MediaPlayer mPlayer = MediaPlayer.create(this, getResources().getIdentifier(nameOfFile, "raw", getPackageName()));
   mPlayer.start();
}

Learn ReactJs, React Native from akashmittal.com