Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 1.33 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Pass an Array of audio files to ArrayList
  2. int[] lessonClips = { R.raw.button_a, R.raw.button_2, R.raw.button_3,
  3.                 R.raw.button_4, R.raw.button_5, R.raw.button_6 };
  4.        
  5. public ArrayList<HashMap<String, String>> getPlayList(){
  6.                     File home = new File(new String("/sdcard/audio"));
  7.  
  8.                     if (home.listFiles(new FileExtensionFilter()).length > 0) {
  9.                         for (File file : home.listFiles(new FileExtensionFilter())) {
  10.                             HashMap<String, String> song = new HashMap<String, String>();
  11.                             song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
  12.                             song.put("songPath", file.getPath());
  13.  
  14.                             // Adding each song to SongList
  15.                             songsList.add(song);
  16.                         }
  17.                     }
  18.                     // return songs list array
  19.                     return songsList;
  20.                 }
  21.        
  22. public class Song {
  23.    String title;
  24.    String path;
  25.    int resource; //R.raw.*
  26.    //setters and getters
  27. }
  28.        
  29. ArrayList<String> songList;
  30.        
  31. ArrayList<Song> songList; //10s' suggestion.
  32.        
  33. for(int x = 0; x < lessonClips.length; x++)
  34. {
  35.     songList.add(getApplicationContext().getResources().
  36.                getResourceEntryName(lessonClips[x]);
  37. }