2011-05-02 103 views

回答

2

像這樣的東西應該工作

ContentResolver contentResolver = getContentResolver(); 
String columns = { 
    MediaColumns.TITLE, 
    AudioColumns.DURATION, 
    MediaColumns.DATA 
    // add more columns if you want to fetch more data 
}; 

Cursor cursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,columns, null, null, null); 

while(cursor.moveToNext()) { 
    String title = cursor.getString(cursor.getColumnIndex(MediaColumns.TITLE)); 
    Long duration = cursor.getLong(cursor.getColumnIndex(AudioColumns.DURATION)); 
    String data = cursor.getString(cursor.getColumnIndex(MediaColumns.DATA)); 
    // handle song here 
} 
+0

我用你的代碼如下我得到IllegalStateException異常。我的代碼: final String [] proj = {MediaStore.Audio.Media._ID,MediaStore.Audio.Media.DATA,MediaStore.Audio.Media.DISPLAY_NAME,MediaStore.Audio.Media.SIZE}; cursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,proj,null,null,null); (cursor.moveToNext()){ String title = cursor.getString(cursor.getColumnIndex(MediaColumns.DISPLAY_NAME)); \t \t values.put(「bpm」,0); \t \t \t values.put(「songname」,title); \t \t \t \t db.insert(「songs」,null,values); //在這裏處理歌曲 } – 2011-05-02 08:59:29

+0

你從哪裏得到IllegalStateException – 2011-05-02 09:02:56

+0

我在String title = cursor.getString(cursor.getColumnIndex(MediaColumns.TITLE)); – 2011-05-02 09:38:42

相關問題