我正在尝试创建一个音乐专辑应用程序,但我应该将歌曲复制到SD卡,复制应用程序的大小,这对于低内存空间设备是不合适的。我想访问原始文件夹本身的直接地址(而不是其中的文件)。有没有更好的方法来执行此操作?
我的歌曲管理器代码,从文件夹中获取所有.mp3文件:
public class SongsManager {
// SDCard Path
final String MEDIA_PATH = new String(Environment.getExternalStorageDirectory().getPath()+"/.piano/");
private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
// Constructor
public SongsManager(){
}
/**
* Function to read all mp3 files from sdcard
* and store the details in ArrayList
* */
public ArrayList<HashMap<String, String>> getPlayList(){
File home = new File(MEDIA_PATH);
if (home.listFiles(new FileExtensionFilter()).length > 0) {
for (File file : home.listFiles(new FileExtensionFilter())) {
HashMap<String, String> song = new HashMap<String, String>();
song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
song.put("songPath", file.getPath());
// Adding each song to SongList
songsList.add(song);
}
}
// return songs list array
return songsList;
}
/**
* Class to filter files which are having .mp3 extension
* */
class FileExtensionFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".mp3") || name.endsWith(".MP3"));
}
}
}
如果我能够将原始文件夹的地址传递给MEDIA_PATH,问题就会解决。
答案 0 :(得分:0)
使用
getResources().openRawResource(R.raw.song);