Search code examples
androidstringaudiomedia-player

Android Loading & Playing Sound Based on String


I'm currently working on a simple Android app, and right now I am trying to get it to load in and play sounds. The problem I am faced with is that I want the sound it uses to be based on a string (With the same name as the sound file). The reason for this is simplicity in both the code and adding on to it.

Now unfortunately I can't just slap a string in place of referencing the actual sound, but is there some way for me to compare a string to the entire raw folder to find the matching sound, or some other alternative short of defining every sound manually?

Thank you for your time.


Solution

  • This page explains how to use getresources().getidentifier().