如何找到SD卡上的所有音频文件(日食,机器人) [英] How to find all audio files on SDCard (eclipse, android)

查看:218
本文介绍了如何找到SD卡上的所有音频文件(日食,机器人)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经这样code ...但我也想搜索线槽子文件夹,而不仅仅是搜索槽sdcard.sorry,我的英语;)
感谢帮助,vinzenz

i have already this code...but i want to search also trough the sub folders instead of just searching trough sdcard.sorry for my english ;) thanks for helping, vinzenz

public class SongsManager {
// SDCard Path
final String MEDIA_PATH = new String("/sdcard/");
private ArrayList<HashMap<String, String>> songsList = new        ArrayList<HashMap<String, String>>();

// Constructor
public SongsManager(){
    **strong text**
 }

/**
 * 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;
}

}

推荐答案

考虑到媒体,从SD卡扫描,可以从MediaStore获取此信息

Considering that Media is scanned from sdcard, you can get this information from MediaStore

 musiccursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            proj, MediaStore.Audio.Media.MIME_TYPE  + "= audio/mpeg", null, null);

int column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);


while(musiccursor.moveToNext()){

String path = musiccursor.get(column_index);
//path is your music path, use this
}

这篇关于如何找到SD卡上的所有音频文件(日食,机器人)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆