I'm trying to make a music album app that has some song in it and can play them. I made the player but now I am stuck because my player , uses musics in an especial address on sd card and I need to either copy audios or use my installed app's asset (or row) folder that is on device (I don't know if there is this folder on phone's memory or not). If there is a better way please let me know.
here is my code:
public class SongsManager {
// SDCard Path
final String MEDIA_PATH = new String("/sdcard/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;
}
Asset Folder is readable folder you can't write or store files from SD card to assets folder. You can add some Mp3 files to your asset folder initially before preparing final build of your projects and can copy them to SD Card later.
Now you can access these files from SD Card or assets. You can store Mp3 songs from SD card to server only using Some RESTful POST web services.
Here is the link to copy files from assets to sd card
How to copy files from 'assets' folder to sdcard?
Hope it will help you