Accessing media on external sdcard

All your problems with Audio, Video and Images.

Accessing media on external sdcard

Postby Mag1c » Mon Feb 28, 2011 1:13 pm

Hey,
I'm writing an app that have lots of audio and images files, it has ~6000 .mp3 files that each one is ~7 seconds, in total ~400 mb
So I need to put them on the external sd-card. I'm using android 1.5.
The user will put the media manually to the sd-card

1. How can I enter the files in the external sdcard through code?
2. In the Samsung Galaxy S, the external sdcard is in /sdcard/external_sd .... do all android devices have the same path?

Thanks.
Mag1c
Developer
Developer
 
Posts: 28
Joined: Tue Jan 04, 2011 12:15 am

Top

Re: Accessing media on external sdcard

Postby strider2023 » Mon Feb 28, 2011 1:54 pm

Mag1c could you please tell me more about what you are trying to create here. The way I see you can directly copy paste the files if the user will put the media manually.
strider2023
Senior Developer
Senior Developer
 
Posts: 126
Joined: Tue Mar 02, 2010 6:34 am
Location: Chennai, India

Re: Accessing media on external sdcard

Postby Mag1c » Mon Feb 28, 2011 2:57 pm

Yes the user will paste the files in the external sd
Though I want to know how can I read the files to play them in my app..
How to access the folder etc
Mag1c
Developer
Developer
 
Posts: 28
Joined: Tue Jan 04, 2011 12:15 am

Re: Accessing media on external sdcard

Postby strider2023 » Tue Mar 01, 2011 4:19 pm

Well first you need to define the path where you have your song. Then populate the songs...here is how you would do it...

Code: Select all
public static final String MEDIA_PATH = new String("/sdcard/");
private List<String> songs = new ArrayList<String>();
...
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ...
        ...
        updateSongList();
}
...
     public void updateSongList() {
          File home = new File(MEDIA_PATH);
      //mpInterface.clearPlaylist();
      if (home.listFiles(new Mp3Filter()).length > 0) {
         for (File file : home.listFiles(new Mp3Filter())) {
            songs.add(file.getName());
             //mpInterface.addSongPlaylist(file.getName());
         }
      }
    }
   
    class Mp3Filter implements FilenameFilter {
          public boolean accept(File dir, String name) {
             return (name.endsWith(".mp3"));
          }
    }
strider2023
Senior Developer
Senior Developer
 
Posts: 126
Joined: Tue Mar 02, 2010 6:34 am
Location: Chennai, India

Re: Accessing media on external sdcard

Postby Mag1c » Tue Mar 01, 2011 7:20 pm

Thanks strider2023, Worked like a charm
Though the only problem is that the List is the other way around, i mean "audio001, audio002,...audio100"... list[1] is audio100 not 001!
Mag1c
Developer
Developer
 
Posts: 28
Joined: Tue Jan 04, 2011 12:15 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 19 guests