List of sounds

All your problems with Audio, Video and Images.

List of sounds

Postby Viktoriia » Tue Jul 26, 2011 5:21 pm

Hi all!
I have a little problem.
I found
Code: Select all
class Mp3Filter implements FilenameFilter {
    public boolean accept(File dir, String name) {
        return (name.endsWith(".mp3"));
    }
}

public class MusicDroid extends ListActivity {
   
   private static final String MEDIA_PATH = new String("/sdcard/");
   private List<String> songs = new ArrayList<String>();
   private MediaPlayer mp = new MediaPlayer();
   
   @Override
    public void onCreate(Bundle icicle) {
        try {
           super.onCreate(icicle);
           setContentView(R.layout.songlist);
           updateSongList();
        } catch (NullPointerException e) {
           Log.v(getString(R.string.app_name), e.getMessage());
        }
    }
   
    public void updateSongList() {
       File home = new File(MEDIA_PATH);
      if (home.listFiles( new Mp3Filter()).length > 0) {
          for (File file : home.listFiles( new Mp3Filter())) {
             songs.add(file.getName());
          }
      
          ArrayAdapter<String> songList = new ArrayAdapter<String>(this,R.layout.song_item,songs);
          setListAdapter(songList);
      }       
    }
   
   @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
      try {
         
         mp.reset();
         mp.setDataSource(MEDIA_PATH + songs.get(position));
         mp.prepare();
         mp.start();
      } catch(IOException e) {
         Log.v(getString(R.string.app_name), e.getMessage());
      }
   }
}

but I have private Integer[] music = { R.raw.crash_1, R.raw.crash_2, R.raw.crash_3,
R.raw.outboard_boat_ride, R.raw.rowing_river_wey,
R.raw.sports_speed_boat };
How can I save my array in the file or show my array in list?
Thank you in advance!
Viktoriia
Freshman
Freshman
 
Posts: 5
Joined: Wed Jun 08, 2011 11:24 am

Top

Re: List of sounds

Postby Viktoriia » Thu Jul 28, 2011 3:49 pm

Any ideas how can I save this list of songs in file on sd card?
Viktoriia
Freshman
Freshman
 
Posts: 5
Joined: Wed Jun 08, 2011 11:24 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 19 guests