Playing Audio files from SD card

只愿长相守 提交于 2019-12-11 07:25:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!