问题
I wanted to load files from the SD card into a SoundPool as well as ringtones. I am able to successfully get the path of the files, and I am able to play them with MediaPlayer. However, I need the functionality of the SoundPool. I have tried SoundPool.load(String, int) but it appears to not load the file. Is it possible to load files from the SD card into a SoundPool, or is there a better way to do this?
回答1:
You can use android.os.Environment.getExternalStorageDirectory()
to get the directory to your sdcard and append the file and extension, you can then use SoundPool withload(String path, int priority)
, to access your file.
Or while not recommended you can even hardcode your path to "/sdcard/".
If the problem is not with getting the soundfile path then you can take a look at Creating Sound Effects in Android
来源:https://stackoverflow.com/questions/7879053/playing-audio-files-from-sd-card