在Android上获取本地音频可以通过以下步骤实现:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
ContentResolver contentResolver = getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String[] projection = { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA };
Cursor cursor = contentResolver.query(uri, projection, null, null, null);
if (cursor != null) {
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
// 在这里可以处理获取到的音频文件信息
}
cursor.close();
}
注意:以上代码只是一个示例,具体的操作可以根据需求进行调整。